performance - SQL - fastest interval lookup -



performance - SQL - fastest interval lookup -

i have table geoip 3 columns: bigint start, bigint end , varchar country (actually, ip country mapping). intervals specified start , end columns, sorted , have no overlaps or gaps. table has lot of rows (hundred thousands).

table users 3 columns: int userid, varchar login , bigint ip.

what fastest sql way (statement , table architecture) bring together these tables assign country each user? i'd have view.

at moment utilize cross apply works pretty slow.

update:

i wrong in initial question. fortunately interval lookup works smoothly. real issue in string concatenations geoip.country + ' ' + geoip.region + ' ' + geoip.city region. badly changed execution plan. switching calculations select user function solved problem.

i had similar problem 1 time ip range table doing total scans when querying range containing given element (on oracle 10g years ago):

select country geoip ? between start , end

the solution rewrite query so:

select country geoip start = ( select max(start) geoip start <= ? ) , end >= ?

perhaps technique speed query? i'm not 100% same issue, since looking join, perhaps can utilize theory.

alternative solution

the real issue may in string concatenations geoip.country + ' ' + geoip.region + ' ' + geoip.city region. can badly changed execution plan. switching calculations select user function may solve problem.

sql performance join

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -