在书上看了很多关于查询的文章,说法不一,但是楼主你这么写确实会很慢.根据我的测试,影响查询速度最大的因素是关联列的索引的使用,当然,in,(+)也会对查询有一定的影响. 首先建索引,比如在a_id,b_id字段上建索引,在然后 select a.* from a, b, c where 1=1 and b.a_id=a.a_id and c.b_id=b.b_id
2. 一般来说 NOT EXISTS 要比NOT IN 要快, 而EXISTS 却比IN要慢 对于EXISTS,只要子查询有记录,就会返回TRUE,并不会把子查询全部执行完毕。 而对于IN,是需要把子查询全部执行完毕,得到所有的结果后,再来一个一个比较。
首先确定A表在a_id字段上已建索引,B表a_id,b_id字段上已建索引,C表b_id字段上已建索引,然后把你上面的语句改成: select * from A,B,C where A.a_id=B.a_id And B.b_id=C.b_id;
你应该使用JOIN的概念来进行查询,而且要将数据量小的表作为判断条件的前半部分,这样,数据库只要所有数据量小的表就可以了 select * from a, b, c where b.id = a.id and b.id = c.id
楼主用的是select * from a where ..... 可是各位DD们用的都是select * from a,b,c where ..... 为什么from后都是a,b,c啊? 偶是新手别笑我啊.
呵呵,看来这个JOIN问题已经有很多人来解决了, 如果select * from a,b,c where b.id = a.id and b.id = c.id 如果建立了索引之后速度还慢,那就得考虑你的数据是不是得分区存储了
1. select a.* from a,b,c where b.id = a.id and b.id = c.id 2. a,b,c物理上分别放在不同的硬盘上3。因为只有key的条件不用再作索引
4。快的方法 select a.id into idtem from a,b,c where b.id = a.id and b.id = c.id loop select * from a where id = idtem end loop这样处理最快。
to ' yazoox(考拉) ( 楼主用的是select * from a where ..... 可是各位DD们用的都是select * from a,b,c where ..... 为什么from后都是a,b,c啊? 偶是新手别笑我啊.select * from a where a_id in (select a_id from b where b_id in (select b_id from C)) 他的意思是说 a_id 在 B,C中存在为条件
首先建索引,比如在a_id,b_id字段上建索引,在然后
select
a.*
from
a,
b,
c
where
1=1
and b.a_id=a.a_id
and c.b_id=b.b_id
对于EXISTS,只要子查询有记录,就会返回TRUE,并不会把子查询全部执行完毕。
而对于IN,是需要把子查询全部执行完毕,得到所有的结果后,再来一个一个比较。
select * from A,B,C where A.a_id=B.a_id And B.b_id=C.b_id;
select * from a, b, c where b.id = a.id and b.id = c.id
可是各位DD们用的都是select * from a,b,c where .....
为什么from后都是a,b,c啊?
偶是新手别笑我啊.
如果select * from a,b,c where b.id = a.id and b.id = c.id 如果建立了索引之后速度还慢,那就得考虑你的数据是不是得分区存储了
select a.id into idtem from a,b,c where b.id = a.id and b.id = c.id
loop
select * from a where id = idtem
end loop这样处理最快。
yazoox(考拉) (
楼主用的是select * from a where .....
可是各位DD们用的都是select * from a,b,c where .....
为什么from后都是a,b,c啊?
偶是新手别笑我啊.select * from a where a_id in (select a_id from b where b_id in (select b_id from C))
他的意思是说 a_id 在 B,C中存在为条件