Oracle EXPLAIN PLAN Utility, Path Information and Execution Statement
Running an EXPLAIN PLAN is a fairly straightforward process.
After the PLAN TABLE has been created, we must populate it with access path information by running the SQL statement prefaced with the following:
EXPLAIN PLAN SET STATEMENT_ID = test1
FOR <<ADD YOUR SQL HERE >>
Once the access path information has been created, we run the plan.sql script, and analyze the output.
The following series of images will demonstrate the process.
Create Plan Table
We create the PLAN TABLE by running the utlxplan.sql script,
Once the PLAN TABLE has been created, we must populate it with access path information.
At this point, the SQL optimizer has only been directed to compute the access place and place it in the PLAN TABLE.
The EXPLAIN PLAN output, if read correctly, reveals vital information.
All SQL tuning experts must be
proficient in reading Oracle execution plans and
understand the steps within explain plans and
the sequence in which the steps are executed.
To successfully understand an explain plan you must know the order that the plan steps are executed.
Oracle SQL tuning DBAs reveal the explain plans to check many things:
Ensure that the tables will be joined in optimal order.
Determine the most restrictive indexes to fetch the rows.
Determine the best internal join method to use (e.g. nested loops, hash join).
Determine that the SQL is executing the steps in the optimal order.
Reading SQL execution plans has always been difficult, but there are some tricks to help determine the correct order that the explain plan steps are executed.
Now that we have a broader understating of how to use the EXPLAIN PLAN, let us try out our new skills by seeing how to detect full-table scans.
Reading Oracle Plan Table
Before moving on to the next lesson, click the Exercise link to try your hand at creating a PLAN table and analyzing an output. Reading Oracle Plan Table.
Oracle Execution Plan
An execution plan shows the detailed steps necessary to execute a SQL statement. These steps are expressed as a set of database operators that consume and produce rows. The order of the operators and their implementations is decided by the query optimizer using a combination of query transformations and physical optimization techniques. While the display is commonly shown in a tabular format, the plan is in fact tree-shaped.
For example, consider the following query based on the SH schema (Sales History):
SELECT prod_category, AVG(amount_sold)
FROM sales s, products p
WHERE p.prod_id = s.prod_id
GROUP BY prod_category;
The tabular representation of this query's plan is:
While the tree-shaped representation of the plan is: