首页 > 数据库技术 > 详细

oracle查询优化之子查询条件优化

时间:2017-08-18 14:01:37      阅读:244      评论:0      收藏:0      [点我收藏+]

  环境:oracle 11g

  现有a表与b表通过a01字段关联,要查询出a表的数据在b表没有数据的数据;sql如下

select count(1) from (select a.*,(select count(1)  from b where b.a01=a.a01) as flag from a) where flag=0

  因为flag是虚拟字段没有走不了索引导致这条sql执行起来特别慢 310W条数据查总数花费2秒左右。

  利用not exists优化sql如下

select count(1) from a where not exists(select 1 from b where a.a01=b.b01)

  利用not exists走索引,执行花费时间大约为0.2秒

oracle查询优化之子查询条件优化

原文:http://www.cnblogs.com/many-object/p/7389177.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!