Improving system performance-Thoughts on SQL statement Optimization

Source: Internet
Author: User

In the process of software development, the scalability of the system has been noticed from beginning to end, but at the same time, the system performance is also concerned. As a part of the system performance, SQL statements cannot be ignored, starting from today, I will talk about my understanding and cognition of SQL statement Optimization Based on my development experience:

1. Small table-driven big table in the joint query statement:

Joint query is a commonly used query method. Left join, right join, internal join, and so on are occasionally applied in the query statement, however, in this process, if we can determine the data volume of each table, it would be better. In this case, the from should be followed by a table with a small amount of data. Why? For example, if Table a has 1000 data records and table B has 20 data records, use a left join for joint query. If table a drives table B, table B will be accessed 1000 times, however, if Table B drives Table a, as long as Table a is accessed 20 times, its performance can be imagined.

2. Do not use in + subqueries

Please note that I didn't mean not to use in queries here. If the value in is given rather than obtained from other tables by using select, The in keyword is understandable, however, if the data in is obtained from other tables through the select statement, we strongly recommend that you change it to the Union query method. For details, refer to the blog 《SQL statement Optimization-in, not in, exists, not exists, left join... on".

3. Pay attention to the order of the query conditions following the where keyword, put the query conditions that have not been set to the end, and put the given non-fuzzy query conditions at the top;

This blog is continuously updated and will be available soon.

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.