Comparative Analysis of Oracle in and exists not in and not exists

Source: Internet
Author: User

Let's sum up and answer these two common questions that most netizens are concerned about.

Differences between in and exist

From the perspective of SQL programming, in is intuitive, and exists is not intuitive. There is one more select,
In can be used for subqueries, while exists seems to be used only for subqueries.

In terms of performance
Exists uses loop. The number of cycles has a large impact. The number of external records must be small, so it doesn't matter if the internal table is used.

In uses hash join, so if the inner table is small, the entire query range will be very small. If the inner table is large, and the External table is very slow, in this case, exists is faster than in.

Difference between not in and not exists

Not in internal and external tables are all scanned, and no index is used;
Not extsts subqueries can use table indexes.

Therefore, we recommend that you use not exists instead of not in.

However, if it is exists and in, it depends on the situation.

Specific instances and execution plans are provided for time.

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.