4 points to be aware of in optimizing SQL statements

Source: Internet
Author: User
Tags numeric sql

1. Try not to perform functional processing of column names. Instead, it is processed for the following values

For example, where col1 =-5 efficiency is higher than where-col1=5 efficiency

The column values are evaluated because of the subsequent conditions. The optimizer cannot use the index under such conditions

Instead, you have to evaluate all the values before you can compare them.

2. Try to use the same value as the play column to operate

If col1 is a numeric type

So for example where col1 = 2 and where col1= ' 2′

The former is more efficient

Because when comparing characters and numeric types,

The engine needs to convert both to double and then compare.

3. Reduce the use of functions

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

And where DateDiff (Day,col1,getdate ()) =0

The latter is used for function processing. So the index on the col1 can't be used anymore.

4. Try not to use or

General conditions for OR

The optimizer typically uses full table scans



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.