SQL Tech Insider -10 in and exists performance comparison

Source: Internet
Author: User
In and Existsin is the appearance and the inner table as a hash connection, and exists is the external loop loop, each loop loop and then query the internal table. The assertion that exists is more efficient than in is inaccurate. If the two table size of the query is equal, then the in and exists are not very different. If one of the two tables is smaller, one is a large table, then the subquery table is large with exists, and the subquery table is small in: For example: Table A (small table), table B (large table) 1:select * from A where CC in (select CC from B) is inefficient, The index of the CC column on table A is used; the select * from A where exists (select cc from B where cc=a.cc) is efficient and uses the index of the CC column on table B. The opposite 2:select * from B where cc in (select CC from a) is highly efficient and uses the index of the CC column on table B; select * from B where exists (select CC from a WHERE cc =b.cc) is inefficient and uses the index of the CC column on table A. Not-in and not-exists if the query statement uses not-in to perform a full-table scan of the outer surface, the index is not used, and the index on the table is still used by not Extsts's subquery. So no matter the table is large, using not exists is faster than not. The difference between in and = select name from student where name in (' Zhang ', ' Wang ', ' Li ', ' Zhao '); with select name from student where Name= ' Zhang ' Or name= ' li ' or name= ' Wang ' or name= ' Zhao ' results are the same.

  

SQL Tech Insider -10 in and exists performance comparison

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.