k***s 发帖数: 277 | 1 q is a table with only one field, snip (int), 180,000 records
ip2country is a table contain ip ranges for each country,
there are about 140,000 records.
我在做如下查询时,非常慢
select q.snip, p.country from q, ip2country as p
where q.snip >= p.ip_range_begin && q.snip <= p.ip_range_end
请问有什么方法可以进行优化?
多谢了 | b******l 发帖数: 261 | 2 where q.snip between p.ip_range_begin and p.ip_range_end.
you should add a join condition for these two tables
【在 k***s 的大作中提到】 : q is a table with only one field, snip (int), 180,000 records : ip2country is a table contain ip ranges for each country, : there are about 140,000 records. : 我在做如下查询时,非常慢 : select q.snip, p.country from q, ip2country as p : where q.snip >= p.ip_range_begin && q.snip <= p.ip_range_end : 请问有什么方法可以进行优化? : 多谢了
| k***s 发帖数: 277 | 3 I'm a newbie, could you give me a example how to do it?
Thanks,
【在 b******l 的大作中提到】 : where q.snip between p.ip_range_begin and p.ip_range_end. : you should add a join condition for these two tables
| w******n 发帖数: 692 | 4 Add index to both tables, which should improve the performance.
【在 k***s 的大作中提到】 : I'm a newbie, could you give me a example how to do it? : Thanks,
| h******i 发帖数: 133 | 5 假如你没有基本的两个TABLE的JOIN,就好比在做Cartesian product,返回的结果
将会是巨大的数目。自然会很慢。。。
SELECT a.id, b.grade
from student a,
grade b
where a.id = b.id
and a.class_date between b.from_date and b.to_date
【在 k***s 的大作中提到】 : I'm a newbie, could you give me a example how to do it? : Thanks,
|
|