in exists 区别
来源:互联网 发布:淘宝开店证件照要求 编辑:程序博客网 时间:2024/05/22 05:31
IN 与 EXISTS 的区别
IN
确定给定的值是否与子查询或列表中的值相匹配。
EXISTS
指定一个子查询,检测行的存在。
分别适用在什么情况?
以子查询 ( select y from T2 )为考虑方向
如果子查询的结果集很大需要消耗很多时间,但是T1比较小执行( select null from t2 where y = x.x )非常快,那么exists就比较适合用在这里
相对应得子查询的结果集比较小的时候就应该使用in.
性能的比较
如果查询的两个表大小相当,那么用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要快。
- in 和 exists 区别
- IN和EXISTS区别
- in 和 exists区别
- in 和 exists区别
- in和exists 区别
- in和exists区别
- in 和 exists区别
- exists in 区别
- in和exists区别
- in 和 exists区别
- exists in 区别
- in exists 区别
- in和exists区别
- in、or、exists区别
- in和exists 区别
- oracle in exists 区别
- exists 和 in 区别
- in 和 exists 区别,not in和not exists区别
- Notification通过Intent传递参数getIntent()为null的问题解决
- OPEN GL实践系列(1)
- GNU/Linux jpg、png、gif 与 eps 格式的相互转换
- LaTeX技巧005:改变文字的前景色和背景色
- HDU 5698 瞬间移动 (2016"百度之星" - 初赛(Astar Round2B) 1003)
- in exists 区别
- Java注解-3种基础注解
- 时间复杂度
- 蓝桥杯 历届试题 矩阵翻硬币(大数开方)
- 金匮要略白话文
- 软件构架求助
- 抽象类和接口区别
- Spring核心技术(五)——Spring中Bean的作用域
- Javaweb项目虚拟路径