SQL query efficiency WHERE statement condition

Source: Internet
Author: User
Indexed columns take precedence, there are indexes to see the amount of data to be queried, less priority

In, not in,<>,is null,is NOT NULL, etc. as the index does not go, try not to use.

The condition order after the WHERE clause has a direct effect on the query of the large data scale, such as

Select * from zl_yhjbqk where dy_dj = ' 1K or less ' and xh_bz=1

Select * from Zl_yhjbqk where xh_bz=1 and dy_dj = ' 1K or less '

The above two SQL Dy_dj and xh_bz two fields are not indexed, so the execution is full table scan, the first SQL DY_DJ = ' 1KV below ' condition in the recordset ratio of 99%, and xh_bz=1 ratio is only 0.5%, at the time of the first SQL 99 The% records are compared DY_DJ and xh_bz, while in the second SQL 0.5% records are compared Dy_dj and xh_bz, in order to conclude that the second SQL CPU utilization is significantly lower than the first one.

SQL query efficiency WHERE statement condition

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.