Question: I need some tips for understanding
the Oracle explain plan. I have been told that reading the
Oracle explain plan will help me identify tuning opportunities, but
the explain plan and how to use it are a mystery to me.
Answer: In the most basic terms, the
Oracle explain plan is a tool that can be used to get Oracle to tell
you how it plans on executing a query. Clearly, this makes the
explain plan a valuable tool for tuning.
Once the Oracle explain plan reveals how it plans on executing
the query in question, the environment can be adjusted to run the
The Oracle explain plan is a statement that returns execution plans for
the requested SELECT, UPDATE, INSERT and DELETE statements.
The execution plan for any given statement shows the operations in
sequence used by Oracle to run that statement.
Information returned by the Oracle explain plan includes:
- the tables referenced in the statement
- the ordering and method with which each table is accessed
- for join operations, the join method for the tables involved
- data operations such as filter or sort included in the
In addition to the information listed above, the Oracle explain plan
table will also contain information on:
The explain plan information is written to an
explain plan table.
It is important to note that the explain plan table must be created
before running the explain plan statement.
Once the Oracle explain plan table has been created, suspect SQL
statements can be evaulated and tuned accordingly.
It is also possible to derive an Oracle explain plan using the
SQL*Plus autotrace function as shown here:
SQL> SELECT *
2 FROM emp
e, dept d
3 WHERE e.deptno = d.deptno
4 AND e.ename = 'SMITH';
The disadvantage of this method is that the statement has to
complete its run in order to be evaluated. If the statement is
truly bad, this could involve a considerable amount of wasted time.
The preferred method would be the
explain plan route.
The explain plan statement generates the execution plan for a
query without executing the query itself, allowing the execution
plan for poorly performing queries to be displayed without impacting
The following example shows how the explain plan statement is
used to generate an execution plan:
SQL> EXPLAIN PLAN FOR
2 SELECT *
3 FROM emp e,
e.deptno = d.deptno
5 AND e.ename = 'SMITH';
If multiple people are accessing the same Oracle explain plan
table, or a history of the Oracle execution plans is to be saved,
the statement_id clause of the Oracle explain plan
statement should be used. This associates a user specified
identifier with each explain plan, which can be used when retrieving
The following example shows how the statement_id is set
using the Oracle explain plan statement.
SQL> EXPLAIN PLAN SET
STATEMENT_ID = 'TIM' FOR
2 SELECT *
3 FROM emp e, dept d
4 WHERE e.deptno =
AND e.ename = 'SMITH'; Explained.
goals of tuning the SQL statements returned by the Oracle
explain plan are fairly simple:
- Eliminate sub-optimal large-table full-table scans:
Ensure that the fastest access path to the data is chosen. The
execution plan "FULL" is the key.
- Use fastest table join method: The
optimizer must choose intelligently between nested loops joins,
hash joins and star transformation join methods and these are
displayed in the execution plan.
- Ensure optimal table-joining order: SQL
will run fastest when the first table joins deliver the smallest
With Oracle 11g,
SQL Plan Management evolves more fully.
Get the Complete
Oracle SQL Tuning Information
The landmark book
SQL Tuning The Definitive Reference" is
filled with valuable information on Oracle SQL Tuning.
This book includes scripts and tools to hypercharge Oracle 11g
performance and you can
for 30% off directly from the publisher.