SQL Optimization Records

Source: Internet
Author: User

1. The law of the WHERE statement

1.1 Avoid using In,not in,or or having in the WHERE clause.

You can use exist and not exist instead of in and not.

You can use table links instead of exist. Having can be replaced by where, if not replaced, can be handled in two steps.

Example

1 SELECT *  From ORDERS WHERE customer_name  not in2 (SELECT customer_name from CUSTOMER)

Optimization

1 SELECT *  From ORDERS WHERE customer_name not exist                                                         2 (SELECT customer_name from CUSTOMER)

1.2 Do not declare numbers in character format, to declare character values in numeric format . (The same date) otherwise invalidates the index, resulting in a full table scan.

Examples use:

SELECT emp.ename, emp.job from emp WHERE emp.empno = 7369; Do not use:
SELECT emp.ename, emp.job from emp WHERE emp.empno = ' 7369 '

2. The rule of the SELECT statement

Restrict the use of select * from table in applications, packages, and procedures.

3. Sorting

Avoid the use of resource-intensive operations, SQL statements with Distinct,union,minus,intersect,order by will start the SQL engine execution, resource-intensive sorting (sort) function. Distinct requires a sort operation, while others need to perform at least two sorting

4. Temporary tables

Careful use of temporal tables can greatly improve system performance

SQL Optimization Records

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.