Oracle Database - Explain Plan

About

EXPLAIN PLAN is the SQL Command that tell you what the query plan for a given SQL would be :

  • if executed it right now
  • in the current session
  • with the current settings

EXPLAIN PLAN cannot tell you what plan was actually used to run a given query in the past because the query could have taken place in a session with very different settings (Example : Sort area size).

Articles Related

Setup for EXPLAIN PLAN

It involves several script in $ORACLE_HOME/rdbms/admin :

  • utlxplan.sql (for UTiLity eXplain PLAN table), which contains a CREATE TABLE statement for a table named PLAN_TABLE. This is the table in which EXPLAIN PLAN places the query plan.
  • utlxplp.sql (for UTiLity eXplain PLan Parallel), which displays the contents of the plan table, including information specific to parallel-query plans.
  • utlxpls.sql (for UTiLity eXplain PLan Serial), which displays the contents of the plan table for normal, serial (non-parallel) plans.

You also need to be aware of an important package DBMS_XPLAN that make very easy to query the plan table.

To set up EXPLAIN PLAN, first create the plan table itself.

gerardnico@orcl>@?/rdbms/admin/utlxplan

Table created.

gerardnico@orcl>desc plan_table

If you want to make EXPLAIN PLAN available to the world out of the box, without set up perform this statements.

Use of EXPLAIN PLAN

The format of the EXPLAIN PLAN command is :

EXPLAIN plan
  [SET statement_id= 'text']
  [INTO [owner.]table_name]
FOR statement;
  • The text in bracket is optionnal.
  • The statement_id allows you to store mutliple plans in the plan table
  • The owner.table_name allow you to use another table than PLAN_TABLE.

Documentation / Reference

  • Bookmark "Oracle Database - Explain Plan" at del.icio.us
  • Bookmark "Oracle Database - Explain Plan" at Digg
  • Bookmark "Oracle Database - Explain Plan" at Ask
  • Bookmark "Oracle Database - Explain Plan" at Google
  • Bookmark "Oracle Database - Explain Plan" at StumbleUpon
  • Bookmark "Oracle Database - Explain Plan" at Technorati
  • Bookmark "Oracle Database - Explain Plan" at Live Bookmarks
  • Bookmark "Oracle Database - Explain Plan" at Yahoo! Myweb
  • Bookmark "Oracle Database - Explain Plan" at Facebook
  • Bookmark "Oracle Database - Explain Plan" at Yahoo! Bookmarks
  • Bookmark "Oracle Database - Explain Plan" at Twitter
  • Bookmark "Oracle Database - Explain Plan" at myAOL
 
database/oracle/explain_plan.txt · Last modified: 2010/11/19 10:35 by gerardnico