由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 请问一个SQL语句的优化问题
相关主题
急问一个关于T-SQL的问题,谢谢请教:如何优化,提取组间最大行
SQL combine two columns from two different tables no shared (转载)how to particially delete record in sql server
如何用SQL语句判断一个TABLE是否存在?help about SQL for ACCESS
如何把Access Table输出为SQL语句?请教请教一个SQL Query
请教一个mysql 排序问题。SQL question
这“精妙sql语句”是错误的吗请教比较两个table,找出相同和不同的records
请求SQL语句外行请教一个简单的SQL: 养宠物罚款
猪一样的队友请教SQL server的一个programming的问题,谢谢
相关话题的讨论汇总
话题: ip2country话题: range话题: table话题: records话题: 优化
进入Database版参与讨论
1 (共1页)
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,

1 (共1页)
进入Database版参与讨论
相关主题
请教SQL server的一个programming的问题,谢谢请教一个mysql 排序问题。
MS T-SQL 问题这“精妙sql语句”是错误的吗
问一个SQL Server的问题请求SQL语句
求教个MS SQL的问题猪一样的队友
急问一个关于T-SQL的问题,谢谢请教:如何优化,提取组间最大行
SQL combine two columns from two different tables no shared (转载)how to particially delete record in sql server
如何用SQL语句判断一个TABLE是否存在?help about SQL for ACCESS
如何把Access Table输出为SQL语句?请教请教一个SQL Query
相关话题的讨论汇总
话题: ip2country话题: range话题: table话题: records话题: 优化