Sud Umm wrote:Now, the table has millions of entries and the input IP addresses count is also pretty big. So it doesn't make sense to fire a query for each input IP address.
Any better way to do this?
Well, assuming:
(a) Your db table does not contain overlapping ranges.
(b) You can insert all the IP addresses to be queried into a temporary table.
then what you're doing is an "inner join" between your monster table and the temp table.
You should probably look up the exact syntax for your db, since different versions of SQL may have different ways of doing it (don't you just love it? The most important data retrieval language on the planet still not standardized after 30+ years

).
However, as others have said, indexing is going to be
very important in terms of performance. I'd say, at the very least:
1. If your db table contains START_IP and END_IP columns, then at least one of them should be indexed.
2. If your temp table is likely to contain more than 50 addresses or so, then it should
also be indexed.
Winston