in和exists
in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询。
如果两个表中一个较小,一个是大表,则子查询表大的用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 与 =的区别
select name from student where name in ('zhang','wang','li','zhao');与
select name from student where name='zhang' or name='li' or
name='wang' or name='zhao'
的结果是相同的。
分享到:
相关推荐
IN 和 EXIST的区别
sql语句中in与exist_not_in与not_exist_的区别
in和exist的区别 从sql编程角度来说,in直观,exists不直观多一个select, in可以用于各种子查询,而exists好像只用于关联子查询 从性能上来看 exists是用loop的方式,循环的次数影响大,外表要记录数少,内表就...
SQL中对not in和not exist查询的替代算法.pdf
且看接下来的具体分析:in其实是将外表和内表进行hash join,exists是先对外表进行loop操作,然后每次loop后再对内表进行查询。 如果两张表大小差不多,那么exists和in的效率差不多。 例如: 一张大表为A,一张小表B...
关于Exists,not Exists.in ,not in效率的说明。关于Exists,not Exists.in ,not in效率的说明。关于Exists,not Exists.in ,not in效率的说明。关于Exists,not Exists.in ,not in效率的说明。关于Exists,not Exists.in...
MySQL exists 和in 详解及区别 有一个查询如下: SELECT c.CustomerId, CompanyName FROM Customers c WHERE EXISTS( SELECT OrderID FROM Orders o WHERE o.CustomerID = cu.CustomerID) 这里面的EXISTS是如何...
有时候eclipse或者myeclipse导入项目的时候会发生上面两个错误,IDE不允许我们导入。具体原因是在IDE的workspace中已经存在了相同名字的项目,所以不能导入。
oracle中exists_和in的效率问题详解
eXist:原生XML数据库和应用平台
“exists”和“in”的效率问题,不同的语句exists和in效率有所不同
mysql not in、left join、IS NULL、NOT EXISTS 效率问题记录,需要的朋友可以参考下。
I had worked with concurrency in several languages, but I had never worked in a language that made concurrency so easy (which is not to say they don’t exist; I just hadn’t used any). I had found my...
Not-exist-in-douban 如何贡献 请提交到 index.md 文件
This is a very popular library that solves a lot of fundamental problems in NLP - and you can use it in conjunction with other libraries in your data analysis pipeline. Next we’ll look at “latent...
eXist-db XML原生数据库 XML数据库
eXist数据库的部署文件,可直接部署在Tomcat下