Skip to main content

Seeing the execution plan

When to use it

Once you have a SQL_ID and want to see how the database is running that statement.

Run this

Starter query written for this guide:

-- Plan currently in memory
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('<SQL_ID>', NULL, 'TYPICAL'));

-- Plans kept in AWR (needs Diagnostics Pack)
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_AWR('<SQL_ID>'));

Scripts on the shelf: 02_show_execution_plan_history.sql (Performance › AWR analysis › AWR execution history): historical plan of a SQL_ID from AWR. Edit the SQL_ID inside the file before you run it. For a full guided analysis see Reference › Performance and tuning › Execution Plan Analysis with DBMS_XPLAN.

How to read the output

  • Read the plan from the most indented line outwards: the deepest operations run first.
  • Plan hash value identifies the plan. If today it differs from the value on a day when the statement was fast, the plan changed.
  • TABLE ACCESS FULL on a large table and NESTED LOOPS over a very large number of rows are the two patterns worth pointing out.
  • Rows is the optimizer estimate. A large gap between the estimate and reality usually points to stale statistics.

What to do next

  • Do not try to fix the plan yourself. Collect the SQL_ID, both plan hash values and the times, and hand them over.
  • Statistics can be checked with the pages in Performance › SQL tuning › Stale statistics.

Risk level

READ ONLY Safe to run at any time. It only queries the data dictionary.