Explain Plan for Oracle SQL Statement Analysis

Source: Internet
Author: User

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, and the most internal operations will be first interpreted. If the two operations are on the same layer, the operations with the minimum operation number will be executed first.

1. Install

Run the creation script as sys. The script is located at $ ORACLE_HOME/rdbms/admin/utlxplan. SQL.

The execution method is cp $ ORACLE_HOME/rdbms/admin/utlxplan. SQL/home/utlxplan. SQL.

Run @/home/utlxplan. SQL in the database.

After execution, a plan table is created in the database to store the analysis information.

2. Use

Syntax:

Explain PLAN [SET STATEMENT_ID [=] <string literal>] [INTO <table_name>]

FOR <SQL _statement>

Where:

STATEMENT_ID: A unique string that distinguishes the current execution PLAN from other execution plans stored in the same PLAN.

TABLE_NAME: the name of the plan table. Its structure is shown in the preceding figure. You can set this name as needed.

SQL _STATEMENT: The real SQL statement to be analyzed

For example:

Explain plan set statement_id = 't_ test' for select * from T;

Analysis:

SQL> SELECT A. OPERATION, OPTIONS, OBJECT_NAME, OBJECT_TYPE, ID, PARENT_ID

2 FROM PLAN_TABLE

3 WHERE STATEMENT_ID = 't_ Test'

4 order by Id;

Grant all on plan_table to public; # authorize all users

To use autotrace in SQL * plus. Perform the following operations:

Create a role plustrace in the database and run the script plustrce with the sys user. SQL to create this role. The script is in the directory (UNIX: $ ORACLE_HOME/sqlplus/admin, Windows: % ORACLE_HOME %/sqlplus/admin;

The method is the same as ultxplain. SQL.

Authorization: grant the plustrace permission to the user who needs autotrace

Grant plustruce to public;

Start and close autotrace:

Set autotrace on/off;

Show only execution plans

Set autotrace on explain;

Show statistics only:

Set autotrace on statistics;

Display the execution plan and block the execution results;

Set autotrace on traceonly;

Display only the execution plan and block the execution result:

Set autotrace on traceonly explain;

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.