![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
On Aug 31, 4:55 am, Lennart Jonsson<erik.lennart.jons... (AT) gmail (DOT) com wrote: On 2010-08-30 12:21, Andrew C. wrote: [...] However, I would like to perform a similar lookup for all IP addresses in the 'addresses' table I mentioned earlier (the one with the list of IP addresses in the 'ip' column)... but I can't work out how to JOIN the 'addresses' and 'countries' tables using the 'WHERE (ip-to-lookup)<= ip_to ORDER BY ip_to LIMIT 1' type approach, assuming there's even a way of doing this. Thanks in advance for any advice on how to get this approach to work when JOINing twoo tables, or even for any suggestions on a better approach to looking up country code via IP address! :-) I assume countries is a rather small table so there should be no problem adding indexes like: create index ... on countries (ip_from, ip_to) ... create index ... on countries (ip_to, ip_from) ... I imagine a query like: SELECT a..., c.code FROM countries c JOIN addresses a ON a.ip_address between c.ip_from and c.ip_to will perform reasonable well /Lennart No, it does not... 100 rows in 13.5s (I'm having the same issue) |
#12
| |||
| |||
|
|
On Aug 31, 4:55 am, Lennart Jonsson <erik.lennart.jons... (AT) gmail (DOT) com wrote: On 2010-08-30 12:21, Andrew C. wrote: [...] However, I would like to perform a similar lookup for all IP addresses in the 'addresses' table I mentioned earlier (the one with the list of IP addresses in the 'ip' column)... but I can't work out how to JOIN the 'addresses' and 'countries' tables using the 'WHERE (ip-to-lookup) <= ip_to ORDER BY ip_to LIMIT 1' type approach, assuming there's even a way of doing this. Thanks in advance for any advice on how to get this approach to work when JOINing twoo tables, or even for any suggestions on a better approach to looking up country code via IP address! :-) I assume countries is a rather small table so there should be no problem adding indexes like: create index ... on countries (ip_from, ip_to) ... create index ... on countries (ip_to, ip_from) ... I imagine a query like: SELECT a..., c.code FROM countries c JOIN addresses a ON a.ip_address between c.ip_from and c.ip_to will perform reasonable well /Lennart No, it does not... 100 rows in 13.5s (I'm having the same issue) |
![]() |
| Thread Tools | |
| Display Modes | |
| |