Notes for optimizing SQL statements

Source: Internet
Author: User

1. Try not to perform function processing on the column name. It processes the subsequent values.

For example, the efficiency of where col1 =-5 is higher than that of where-col1 = 5.

The column value is calculated based on the following conditions. The optimizer cannot use indexes under such conditions.

Instead, it is necessary to calculate all values before comparison.

2. Try to use the same value as the number of drama columns for operations

If col1 is Numeric

For example, where col1 = 2 and where col1 = '2 ′

The former is more efficient.

Because when comparing characters and numbers

The engine needs to convert both of them into dual-precision and then compare them.

3. Reduce the use of functions

For example, where col1> = '2017-10-26 'and col1 <= '2017-10-27 ′

And where datediff (day, col1, getdate () = 0

The latter uses function processing. So the index on col1 cannot be used again.

4. Try not to use OR

Generally, for conditions of OR

Optimizer generally uses full table Scan
 

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.