首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

exists和in的执行效率没有区别,有图有真相,该如何解决

2012-03-13 
exists和in的执行效率没有区别,有图有真相select * from syscolumns where id in(select id from sysobjec

exists和in的执行效率没有区别,有图有真相
select * from syscolumns where id in(select id from sysobjects)
select * from syscolumns a where exists(select id from sysobjects where id=a.id)
在查询分析器中,查看以上两句的执行计划,两个的执行成本各占50%,完全一样。
而且执行的步骤也完全相同,截图奉上。
大侠们能给解释一下吗?


[解决办法]
select * from 大表 where cc in (小表)
select * from 小表 where exists(大表)

表A(小表),表B(大表)

1:select * from A where cc in (select cc from B) 
效率低,用到了A表上cc列的索引;
select * from A where exists(select cc from B where cc=A.cc) 
效率高,用到了B表上cc列的索引。

select * from table where id in('1','2')

select * from table t where exists(select id from table where id=t.id) 


你数据量不够大
[解决办法]
执行步骤是一样的,加上not就不一样了
[解决办法]
参考:
http://www.cnblogs.com/haibin168/archive/2011/02/20/1959170.html

数据量较小的时候,一般差距不明显。

[解决办法]
数据量不是很大的情况下是没有多大区别的
[解决办法]

探讨

我到底是结贴呢? 结贴呢? 还是结贴呢?

[解决办法]
exists和in的执行效率,大部分情况下是一样的.

热点排行