再一次见证mssql中in 与exist的区别

 见下面代码

    /*+' select * from '+@strDBName +'.dbo.m_aic where nodeid not in(select nodeid from @tmpAIC) '
*/
    /*+' select * from '+@strDBName +'.dbo.m_aic  as m where not exists  (select 1 from @tmpAIC where nodeid = m.nodeid) '
*/

第一行是用了in

第二行用了exists

之前看书就听过说由于exist会一遇到命中条件就返回,而in要扫整张表,所以exists一般会比in快,,

 

由于上面的语句要查另一个台服务器的表(用了链接服务器),所以这种差距变成了

24min+

11sec的相异.....唉....

posted on 2013-08-13 13:24  Orz..  阅读(222)  评论(0编辑  收藏  举报

导航