SQL SERVER - Efficiently joining two tables using BETWEEN operator -
i've seen similar posts, however, no conclusive answers.
i using geolite (free database) lookup ip block geo ip, , in bulk-
the respective ip's converted ipblocks, , sit table ( l ).
every ipblock falls within range (between startipnum , endipnum), sits in table ( g ).
the query below works, however, extremely inefficient since need perform on large time period -
select l.ipaddress, g.locid l inner join g on l.ipblock between g.startipnum , g.endipnum
both tables indexed (g compound indexed),
a hash join cannot performed since join made on between operator.
is feasible option restructure table g ? or there way?
the best index a single query 1 has columns in where
/ join
clause in nodes, , columns in select
clause in leaf (if not in node already).
try putting index on table l
, see if performance improves:
create index idx_l_ipblock on l (ipblock) include (ipaddress)
Comments
Post a Comment