SQL Optimization (Oracle)-Part III Summary of SQL optimizations

Source: Internet
Author: User

The third part of SQL optimization summary
1. Optimization of general principles
2. Specific considerations

1. General principles of SQL optimization
1) Target: Reduce server resource consumption (mainly disk IO)
2) Design:
1. Rely on the Oracle optimizer as much as possible
2. Appropriate index (data repeat large column do not resume binary tree index, you can use the bitmap index; tables with frequent data operations, indexes need to be rebuilt periodically to reduce failed indexes and fragmentation)
3) Code:
1. Using the index
2. Reasonable use of temporary tables
3. Avoid writing overly complex SQL;
4. Minimize the granularity of transactions

2. Specific considerations
1) Use the identified column names as much as possible when querying
2) use as few nested subqueries as possible, which consumes CPU resources
3) When querying multiple tables, select the most efficient table name order
    The Oracle parser processes the table from right to left, so the table with fewer records is placed on the right (the rightmost table is the base table, drivering table is processed first), and if more than 3 tables join the query, select the crosstab as the base table
4) or more than multiple queries, use union ALL (try to use UNION all instead of union) Junction (for indexed columns)
5) Commit the transaction as much as possible, release the resources, unlock, release the log in time
6) Frequently accessed tables can be placed in memory
7) Avoid complex multi-table associations
8) Avoid distinct,union (and set), minus (difference), intersect (intersection), order by, and other resource-intensive operations, because the resource-intensive sorting function is performed
9) Replace distinct with exists
Select C.distinct c.classname, C.classid, Classno from student S, Class C where s.classno= C.classno;
--Replaced by
Select ClassName, ClassID, Classno from class C where exists (SELECT * from student s where S.classno = C.classno);

Delete can be rolled back without commit, not rollback after truncate, short execution time
11) Use the alias of the table to reduce the parsing time
exists and in the choice of the question, different times differentiated treatment
13) Fair use index

SQL Optimization (Oracle)-Part III Summary of SQL optimizations

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.