The Efficiency Analysis and Improvement Methods of left join in SQL, leftjoin

Source: Internet
Author: User

The Efficiency Analysis and Improvement Methods of left join in SQL, leftjoin

As the data volume and access volume of websites increase, the access speed slows down, so I began to find a solution to the slow speed of optimization.

The following is an SQL analysis process in the program. Of course, the execution efficiency of the program is not only about SQL statements, but also about server configuration, network speed, programming language, and other methods, today, let's analyzeEfficiency of left join in SQL statements

The SQL statement contains the following information:

1. SQL contains data processing functions, such as nvl and case when functions.

2. SQL contains inner join, left join, and other associations.

3. Sorting and paging in SQL

The following is the analysis process.

1. First, the sorting is removed, and the speed is indeed very fast, but there is no way, the sorting is necessary, just to prove that the sorting is indeed very resource-consuming.

2. Remove functions such as nvl and case when, and the result speed is almost unchanged.

3. Remove the inner join table at a speed of dozens of milliseconds.

4. Remove the left join table and increase the speed from 4 seconds to 1 second.

In summary, left join is the culprit of slow speed.Add left join fields as indexesIn the test, it is found that the speed can be kept at around 1 second. Solve the problem.

Conclusion: left join is a resource-consuming operation. If the associated fields are not indexed, the speed is very slow. Therefore, if left join is used,It is best to use index fields for Association. OrAdd an index to the associated field

Some people also said on the Internet that the table data on the Right of left join should be filled and left join should be replaced with inner join. I have tried it. The speed is indeed much faster, but this method is not tested considering the data volume.

Related Article

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.