Partial SQL Optimizations

Source: Internet
Author: User

1. Table name Order: does not affect the business logic case, the general case of large table in the left, the small table in the right; the crosstab appears above the three tables, then the cross table is in front.
2.WHERE clause order: Execution sequence Oracle from right to left, the efficiency is basically the same;
The right table condition of the 3.JOIN table is written as far as possible on, not after where (note: There is a difference between using a left connection);
4. The joins of several large tables should be paged and concatenated as far as possible;
5. Avoid full table scan:
5.1 Avoid function or expression operations on indexed columns;
5.2 The index column is preferably not a null column, using is NOT NULL never uses an indexed column, and is null is sometimes not used;
5.3 Avoid using <>! = does not equal the operator, it restricts the index and causes the full table query;
5.4 '%a% ', '%A ' does not use the index, ' A% ' uses the index;
5.5 Non-indexed columns using an OR query can result in a full table query;
5.6 Using not in does not use the index, with not EXISTS or (outer join + condition) substitution;

6. Avoid using "*" in the query results, substituting count (0) for Count (*);
7. Use the table alias to avoid the same column query errors.
8. Using >= instead of >; A1 = a2*100 Alternative A1/a2=100;datetime =to_char (' 20121122 ', ' YYYYMMDD ') Replace To_char (datetime, ' yyyymmdd ') = ' 20121122 '
9. Replace or with union; exists (or outer joins) replace in; (note: In the number if the char<100,int<1000 effect can be, otherwise you have to use other alternative);

Partial SQL Optimizations

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.