Efficient table structure or indexing for searchable IP address ranges in SQL
I have raw data provided to me for a geolocation service, in the form of a
table of IP address ranges mapped to location data.
The addresses are provided as byte-packed integers (one dotted-quad per
byte), permitting easy storage and comparisons, so each row in this table
provides a range low address, a range high address, and some text location
fields. I don't have to/am not able to use CIDR.
The table is several million records.
I don't have strong SQL chops. The code I inherited simply does a sql call
like:
SELECT location FROM geodata WHERE lookup_address >= range_low AND
lookup_address =< range_high
The performance is terrible. My understanding is that this will simply do
a linear search for matching records. To get around this temporarily I
have thrown together a client cache into a tree map to bring this down to
log performance, but a) my memory usage is now hard to justify, and b)
detecting live database updates is a problem I don't really want to tackle
right now.
It seems like this problem must come up now and then in the SQL world for
addresses, telephone numbers, etc.. Is there a "standard" way to organize
and index ranges in a SQL table so that I can get at least log performance
out of a direct SQL query?
No comments:
Post a Comment