SQL优化[18]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 fly_miss 的 blog

select * from table1 where tid in (2,3)

select * from table1 where tid=2 or tid=3

是一样的,都会引起全表扫描,如果tid上有索引,其索引也会失效。

5、尽量少用not

6exists in 的执行效率是一样的

很多资料上都显示说,exists要比in的执行效率要高,同时应尽可能的用not exists来代替not in。但事实上,我试验了一下,发现二者无论是前面带不带not,二者之间的执行效率都是一样的。因为涉及子查询,我们试验这次用sql server自带的pubs数据库。运行前我们可以把sql serverstatistics i/o状态打开。

1select title,price from titles where title_id in (select title_id from sales where qty>30)

本文关键:SQL优化
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top