RelationalDBDesign 





SQL Tuning   «Prev 

Generating Execution Plans

The EXPLAIN PLAN statement enables you to examine the execution plan that the optimizer chose for a SQL statement. When the statement is issued, the optimizer chooses an execution plan and then inserts data describing the plan into a database table. Issue the EXPLAIN PLAN statement and then query the output table.
6.3.1 Executing EXPLAIN PLAN for a Single Statement The basics of using the EXPLAIN PLAN statement are as follows:
  1. Use the SQL script CATPLAN.SQL to create a sample output table called PLAN_TABLE in your schema.
  2. Include the EXPLAIN PLAN FOR clause before the SQL statement.
  3. After issuing the EXPLAIN PLAN statement, use a script or package provided by Oracle Database to display the most recent plan table output.
  4. The execution order in EXPLAIN PLAN output begins with the line that is the furthest indented to the right. The next step is the parent of that line. If two lines are indented equally, then the top line is normally executed first.
To explain a SQL statement, use the EXPLAIN PLAN FOR clause immediately before the statement. For example:
EXPLAIN PLAN FOR
SELECT last_name FROM employees;

Oracle Tuning: The Definitive ReferenceOracle Tuning: The Definitive Reference


The first section deletes all rows from the plan table.
The first section deletes all rows from the plan table

The main part of the SQL populates the plan table with the access path information
The main part of the SQL populates the plan table with the access path information.

The final step displays the access information from the plan table.
The final step displays the access information from the plan table.

The query produces the following output. Here we see the actual access path to the data
The query produces the following output. Here we see the actual access path to the data