Differences between Oracle in and not in actual application

Source: Internet
Author: User

The following article mainly describes the differences between Oracle in and not in actual application. We all know that in many related software systems, the actual performance of the system is largely determined by the performance of the database. I have also done many tests on performance before.

Especially for Oracle, I think we should record some of them to share them with everyone.

This happened when our system was transplanted from sqlserver to Oracle. The user waited for a query operation and the time was unbearable. Our query processing and the original method were as follows, is there something different between sqlserver and Oracle? Let's take a look at what's wrong with Oracle or what's wrong with Oracle?

The business problem can be roughly described as follows: A parent table and a sub-table, the query result is to find the records in the sub-table that do not use the parent table id. In this case, it is estimated that many systems will be involved. Let's take an example:

Table 1: parent table parent

Table 2: child table childen

The parent table stores the parent table, the child table stores the child table, and then uses the pid to associate with the parent table. The result of the query is to find the father who does not have the child.

Let's take a look at the syntax of the query statement:

 
 
  1. select * from parent where id not in (select pid from childen) 

When the sub-table contains 0.5 million records, the query time exceeds 10 seconds, which is far more than one second on the original SQL server. I came up with a solution:

 
 
  1. select * from parent where id in  
  2. ( select id from parent minus select pid from childen )  

Under normal understanding, this statement should be more time-consuming, but the fact is totally unexpected. This statement is not only fast when the sub-table has a large number of records, in the case of a small amount of data in a sub-table, the speed is also very good, basically completed within 1 second.

This result can clearly prove the huge difference between Oracle in and not in the internal processing of subqueries, I also hope someone will explain the problem.

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.