如果查询的两个表大小相当,那么用in和exists差别不大。

如果两个表中一个较小,一个是大表,则子查询表大的用exists,子查询表小的用in: 
 
  例如:表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列的索引。 
相反的
 
2:
select * from B where cc in (select cc from A) 效率高,用到了B表上cc列的索引;
 
select * from B where exists(select cc from A where cc=B.cc) 效率低,用到了A表上cc列的索引。
 
not in 和not exists如果查询语句使用了not in 那么内外表都进行全表扫描,没有用到索引;而not extsts 的子查询依然能用到表上的索引。所以无论那个表大,用not exists都比not in要快。 
 
 

最新文章

  1. [Evolutionary Algorithm] 进化算法简介
  2. Linux usual cmd
  3. vld使用
  4. Fiddler抓包之IOS
  5. Java——列表框:JList
  6. 小心对待query_cache_size
  7. Web版报表的架构和设计思路
  8. JAVA IO 类库详解
  9. C# "error CS1729: 'XXClass' does not contain a constructor that takes 0 arguments"的解决方案
  10. C++第二课(2013.9.27 )
  11. 基于visual Studio2013解决C语言竞赛题之0609矩阵处理
  12. Windows Phone 8.1 多媒体(1):相片
  13. Unity3d之流光效果
  14. IOS 利用图片设置背景
  15. 02_IO操作的基本规律(InputStream,OutputStream,Reader,Writer,FileReader,FileWriter,BufferedReader,BufferedWri
  16. 【Json】fastjson与jackson常用操作记录
  17. c# 后台处理获取的JSON 数据
  18. python 定时修改数据库
  19. React-使用imutable.js来管理store中的数据
  20. Java如何将每个单词的第一个字符转为大写?

热门文章

  1. 盗取连接你wifi的人的qq
  2. php三种排序算法
  3. oracle字符集问题随笔
  4. electron api sendInputEvent 源码
  5. 【TCP】拥塞控制
  6. libusb 3.0
  7. Linux用户账号文件——passwd
  8. maven项目bulid失败_No compiler is provided in this environment.
  9. 【Python之路】特别篇--事件驱动与异步IO
  10. Ubuntu:查询计算机软硬件信息