匹配IP sql优化

SQL code
ip维表 table_ip
字段有 ip_from,ip_to,city
条数 大概40多万

源表 table_day_log
字段有id,ip
条数大概200万条。

想得到的结果

select t1.id,t1.ip,t1.city from 
table_Day_log t1
left jion table_ip t2 on t1.ip >= t2.ip_from and t1.ip <= t2.ip_to

请教怎么提高查询速度,我需要查询整个表,纠结了好几天没弄好。

作者: sean_zhou   发布时间: 2011-06-15

在 table_ip 表的 ip_from 和 ip_to 列上建索引.
SQL code
select t1.id,t1.ip,t2.city from 
table_Day_log t1
left jion table_ip t2 on t1.ip between t2.ip_from and t2.ip_to

作者: qianjin036a   发布时间: 2011-06-15

在 table_ip 表的 ip_from 和 ip_to 列上建索引.
table_Day_log的 列建索引
查询语句如1楼

作者: cd731107   发布时间: 2011-06-15