Monday, 17 October 2011

Explain Plain

The EXPLAIN PLAN command displays the execution plan chosen by the Oracle optimizer for SELECT, UPDATE, INSERT, and DELETE statements at the current time, with the current set of initialization and session parameters. A statement's execution plan is the sequence of operations that Oracle performs to execute the SQL statement. By examining the execution plan, you can see exactly how Oracle executes the SQL statement. Use EXPLAIN PLAN to determine the Table Access Order, Table Join Types, Index Access to test modifications to improve SQL performance. It's best if you don't blindly evaluate the plan for a statement, and decide to tune it based only on the execution plan. EXPLAIN PLAN results alone cannot tell you which statements will perform well, and which won't. For example, just because EXPLAIN PLAN indicates that a statement will use an Index doesn't mean that the statement will run quickly. The index might be very inefficient. Instead, you should examine the statement's actual RESOURCE CONSUMPTION and the statements ACTUAL RUN TIME. REMEMBER - A low COST doesn't GUARANTEE a FASTER RUN TIME
The AUTOTRACE Command in SQLPlus can be used to generate EXPLAIN PLANS and Run Time Statistics. The EXPLAIN PLAN is generated after the SQL Statement is executed.
Explain Plan (Optimization): To analyze for tuning the SQL statement Explain Plan is used. For that run the UTLXPLAN.SQL script to create table named PLAN_TABLE, for receiving the output of an Explain Plan statement.

Eg. Explain Plan
Set Statement_id 'My Customer'
Into Plan_table
For Select lastname, firstname
From customers
Where state = 'NY'

Output: Select statement_id,operation,options,cost from plan_table;

Statement_id Operation Options Cost
My Customer Select Statement 9
My Customer Table Access Full Access 16

The Explain Plan command of oracle7 uses the current statistics in the data dictionary to do its best to return an accurate execution plan and corresponding cost to executing a statement. However, if statistics are not up-to-date then of course the Explain Plan command might not return an accurate execution plan and cost.

No comments:

Post a Comment