Oracle uses explain plan to analyze SQL statement instance Parsing

Source: Internet
Author: User

OracleUseEXPLAIN PLANThe Method for Analyzing SQL statements is what we will introduce in this article. We know that the explain plan is a good tool for analyzing SQL statements, it can even analyze statements without executing SQL statements. Through analysis, we can know how ORACLE connects to the table, how to scan the table (index scan or full table scan), and the index name used.

You need to interpret the analysis results in the order from inside to outside. the results of the explain plan Analysis are arranged in indent format. The most internal operation is interpreted first. If the two operations are on the same layer, the operation with the minimum operation number will be executed first.

The nested loop is a few operations that do not follow the above rules. The correct execution path is to check the operations that provide data to the nested loop. the operation with the smallest operation number will be processed first.

Through practice, it is easier to use the set trace function in SQLPLUS.

Example:

 
 
  1. SQL> list
  2. 1 SELECT *
  3. 2 FROM dept, emp
  4. 3 * WHERE emp. deptno = dept. deptno
  5. SQL> set autotrace traceonly/* traceonly can not display execution results */
  6. SQL>/
  7. 14 rows selected.
  8. Execution Plan
  9. ----------------------------------------------------------
  10. 0 select statement Optimizer = CHOOSE
  11. 1 0 NESTED LOOPS
  12. 2 1 table access (FULL) OF 'emp'
  13. 3 1 table access (by index rowid) OF 'dept'
  14. 4 3 INDEX (unique scan) OF 'pk _ DEPT '(UNIQUE)
  15. Statistics
  16. ----------------------------------------------------------
  17. 0 recursive cballs
  18. 2 db block gets
  19. 30 consistent gets
  20. 0 physical reads
  21. 0 redo size
  22. 2598 bytes sent via SQL * Net to client
  23. 503 bytes encoded ed via SQL * Net from client
  24. 2 SQL * Net roundtrips to/from client
  25. 0 sorts (memory)
  26. 0 sorts (disk)
  27. 14 rows processed

Through the above analysis, we can see that the actual execution steps are:

1. table access (FULL) OF 'emp'

2. INDEX (unique scan) OF 'pk _ DEPT '(UNIQUE)

3. table access (by index rowid) OF 'dept'

4. nested loops (JOINING 1 AND 3)

Note:Currently, many third-party tools, such as TOAD and ORACLE tools, such as oms SQL Analyze, provide extremely convenient EXPLAIN PLAN tools. Users who like the graphic interface may choose them.

This article describes how to use explain plan to analyze SQL statements in Oracle!

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.