当前位置: 代码迷 >> Oracle开发 >> in 和 not in 的优化,该如何解决
  详细解决方案

in 和 not in 的优化,该如何解决

热度:105   发布时间:2016-04-24 07:40:46.0
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 secondsExecuted in 0.515 secondsExecuted in 0.515 secondsSQL> select count(*) from c01d where c01d27 IN ('2', '8');Executed in 0.547 secondsExecuted in 0.516 secondsExecuted 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,我的理解应该是这样子吧。
  相关解决方案