日期:2014-05-17  浏览次数:20864 次

in 和 not in 的优化
select count(*) from where c01d27 IN ('2', '8')

select count(*) from where c01d27='2' or c01d27='8'

SQL code

SQL> select count(*) from c01d where c01d27='2' or c01d27='8';
Executed in 0.531 seconds
Executed in 0.515 seconds
Executed in 0.515 seconds
SQL> select count(*) from c01d where c01d27 IN ('2', '8');
Executed in 0.547 seconds
Executed in 0.516 seconds
Executed in 0.547 seconds


能看出来好一点...

select count(*) from where c01d26 NOT IN ('2025', '2027', '2029') ;

下周接着测下班了。....



------解决方案--------------------
楼主想说明啥?
------解决方案--------------------
就楼主这个来看,没明显区别!
------解决方案--------------------
这2个的区别不是很明白,学习来了,只知道如果数据量很大的话,可以采用NOT EXIST
------解决方案--------------------
up!
------解决方案--------------------
受教了
------解决方案--------------------
数据量太小,不能说明问题。相差的0.01秒可以归结到误差上
理论上说应该是一样的
------解决方案--------------------
not in时候和not exists时有些差异
not in (NULL) 为true
not exists(NULL) 为false
------解决方案--------------------
子查询中的数据多的时候使用exists/ not exists,子查询中数据少的时候用in/ not in,我的理解应该是这样子吧。