Oracle Execution Plan Analysis

An execution plan is the statement execution method the optimizer chose. It shows, as a tree of operations, which tables are read in which order, with which access paths (full scan, index) and join methods. Tuning means finding where the plan actually does a lot of work and then asking why the optimizer chose that way there. In Oracle, the baseline is the plan with actual execution statistics (ALLSTATS LAST of DBMS_XPLAN.DISPLAY_CURSOR).

Summary

ItemDescription
Expected planEXPLAIN PLAN FOR … + DBMS_XPLAN.DISPLAY. Does not execute. It does not see bind values, so it can differ from the actual plan
Actual planDBMS_XPLAN.DISPLAY_CURSOR(sql_id, child, 'ALLSTATS LAST'). The actual plan attached to the cursor in the shared pool, with the last execution's statistics
Condition for collecting execution statisticsA session with STATISTICS_LEVEL = ALL, or /*+ GATHER_PLAN_STATISTICS */ in the statement
Long statementsSQL Monitor (DBMS_SQL_MONITOR.REPORT_SQL_MONITOR). Shows statements that run longer than 5 seconds or run in parallel, even while they run. Requires the Tuning Pack license
Per-call statistics10046 event trace + TKPROF. For each Parse, Execute, and Fetch: count, cpu, elapsed, disk, query, current, rows
Session statisticsSQL*Plus SET AUTOTRACE. The difference before and after execution in consistent gets, physical reads, sorts, etc.
SandboxRuns every execution with STATISTICS_LEVEL = ALL and shows the ALLSTATS LAST plan (Plan tab, Raw tab), a TKPROF-style call table, and session statistics (Trace tab)

How to Get a Plan

EXPLAIN PLAN: Expected Plan

EXPLAIN PLAN FOR
SELECT o.ord_id, c.cust_nm FROM orders o JOIN customers c ON c.cust_id = o.cust_id WHERE c.grade = :g;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY(format => 'TYPICAL'));

It builds a plan with the current statistics without executing the statement. It does not see the values of bind variables (no Bind Peeking) and assumes every bind type is VARCHAR2, so it can differ from the plan that actually runs. Use it to preview the shape of a statement that takes too long to run.

DISPLAY_CURSOR: Actual Plan and Execution Statistics

-- After running the statement once in a session that collects execution statistics
SELECT sql_id, child_number FROM v$sql WHERE sql_text LIKE 'SELECT o.ord_id%';
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('7kky5zbg5s4v9', 0, 'ALLSTATS LAST'));

It shows the actual plan of the cursor in the shared pool with the actual statistics of the last execution attached. ALLSTATS LAST is the basic format, and you can add +PEEKED_BINDS (the bind values peeked at that time), +OUTLINE (the set of hints that reproduces the plan), +ADAPTIVE (including the discarded branches of an adaptive plan), and +NOTE. Once the cursor is aged out of the shared pool you cannot see it, so look right after execution.

10046 Trace and TKPROF: Per Call

ALTER SESSION SET tracefile_identifier = 'tune';
ALTER SESSION SET events '10046 trace name context forever, level 12';   -- 8: waits, 4: binds
-- Run the statement
ALTER SESSION SET events '10046 trace name context off';
-- On the server: tkprof <trace file> out.txt sys=no sort=exeela,fchela

The TKPROF report produces the table below for each statement. The Calls table in the sandbox Trace tab has the same format (values are computed from the difference in V$SQL before and after execution).

callMeaningWhat to look at
ParseStatement parsing and plan generationIf cpu is large relative to count, it is a hard parse. Misses in library cache during parse: 1 means a hard parse
ExecuteExecution. DML makes its changes hereUsually small for SELECT. Can be large for plans that must finish a sort or hash before the first Fetch
FetchDelivering result rowsMost of the work for SELECT. count is the number of round trips (rows ÷ array size)
Columns disk / query / currentPhysical reads / consistent mode reads / current mode readsquery + current is the logical I/O. For SELECT, current is usually 0
cpu vs elapsedCPU time / elapsed timeThe difference is wait time. Break it down with the wait event list of a level 8 trace

Reading Order

This is actual output from the sandbox for a query of VIP customers' orders from the last 7 days.

------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation          | Name      | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |  OMem |  1Mem | Used-Mem |
------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |           |      1 |        |    143 |00:00:00.03 |   14520 |  13940 |       |       |          |
|*  1 |  HASH JOIN         |           |      1 |  14000 |    143 |00:00:00.03 |   14520 |  13940 |  1980K|  1864K| 1934K (0)|
|*  2 |   TABLE ACCESS FULL| ORDERS    |      1 |  14000 |  14000 |00:00:00.03 |   13943 |  13940 |       |       |          |
|*  3 |   TABLE ACCESS FULL| CUSTOMERS |      1 |  33333 |   1000 |00:00:00.01 |     577 |      0 |       |       |          |
------------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   1 - access("C"."CUST_ID"="O"."CUST_ID")
   2 - filter("O"."ORD_DT">=TO_DATE(' 2025-09-20 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
   3 - filter("C"."GRADE"='VIP')

Note
-----
   - this is an adaptive plan

1. Establish the Execution Order

  • The deeper the indentation, the earlier it starts. Siblings under the same parent run from top to bottom.
  • The first child of a join operation is the driving (for a hash join, Build) set, and the second child is the inner (Probe) set. In the example above, the hash table is built from ORDERS (Id 2) and probed with CUSTOMERS (Id 3).
  • Exception: scalar subqueries in the SELECT list and FILTER subqueries appear separately at the top of the plan, but they execute for every outer row. Check the repeat count in Starts.

2. Find the Operations That Did a Lot of Work

ColumnMeaningHow to read it
StartsNumber of times the operation ranFor the inner side of an NL join and for scalar subqueries, it equals the number of outer rows. Starts × cost of one run is a common bottleneck
E-RowsExpected rows per runWhen comparing, compare E-Rows × Starts with A-Rows
A-RowsSum of actual rows over all runsIf an A-Rows far larger than the result sits in the middle, rows are read and discarded there
BuffersLogical I/O (blocks). Cumulative, including childrenOwn share = own value − sum of children's values. In the example above, the hash join's own share is 0
ReadsDisk reads. CumulativeLarge only on the first run, usually 0 on the second. Compare using the second run
OMem / 1Mem / Used-MemOptimal (memory only) / one-pass / actual work memoryThe number in parentheses in Used-Mem is the pass count. (0) means it finished in memory. If Used-Tmp appears, it spilled to TEMP

In the example above, 13,943 of the 14,520 Buffers are the full read of ORDERS. The result is 143 rows, but 14,000 orders were read.

3. Find Where E-Rows and A-Rows Diverge

The optimizer chooses the join order and method from E-Rows. Id 3 in the example above has E-Rows of 33,333 and A-Rows of 1,000. GRADE has 3 distinct values and no histogram, so the estimate is 100,000 ÷ 3 (Optimizer Statistics). Had it known there are 1,000 VIPs, a plan that finds the VIPs through CUSTOMERS_X1 and joins the orders with NL would have competed (Scenario 29).

  • If the gap is 10x or more, suspect the statistics below it (histograms, correlation between columns). The sandbox Plan tab marks cells where E-Rows × Starts differs from A-Rows by 10x or more.
  • The gap spreads from the bottom to the top. The first place where it diverges at the lowest level is the cause.

4. Check How Conditions Are Used in Predicate Information

  • access: Decides the range to read (the start and end of an index, the key of a hash join). It reduces the amount read.
  • filter: Filters after reading. The ORD_DT condition in the example above was used only as a filter in the full scan, because there is no index that starts with ORD_DT.
  • If INTERNAL_FUNCTION, TO_CHAR(…), or TO_NUMBER(…) appears on the column side of a condition, the column is being transformed and the index cannot be used (Scenario 1).
  • Conditions moved from join conditions (transitive conditions) and conditions generated by the optimizer (LNNVL, SYS_OP_…) also show up here.

5. Check the Note and Transformation Traces

What you seeMeaning
this is an adaptive planA plan that counts rows during execution (STATISTICS COLLECTOR) to choose between NL and hash join. In the +ADAPTIVE format, lines marked with - are the discarded branches
dynamic statistics usedStatistics were missing or insufficient, so sampling happened right before execution
statistics feedback usedA plan whose estimates were corrected with the A-Rows of a previous execution
SQL plan baseline … used / SQL profile … usedA stored plan or profile was applied. Check this if the plan does not change after you edit hints
VW_SQ_n, VW_NSO_nA view that turned a subquery into a join (Unnesting)
VW_SSQ_nA view that turned a scalar subquery into a join
VW_ORE_n, CONCATENATIONThe OR condition was split into branches (OR Expansion)
VW_JF_SET$…, JOIN FILTERBloom filter, join factorization
VIEW PUSHED PREDICATEA join condition was pushed into the view (JPPD)

Common Operations

On the sandbox result screen, the same explanations appear when you hover over an operation name.

OperationMeaningWhen to suspect
TABLE ACCESS FULLReads the whole table (multiblock)The result is small but A-Rows is large. The condition is used only as a filter
TABLE ACCESS BY INDEX ROWID [BATCHED]Reads rows with the ROWIDs the index gaveIndex A-Rows ≫ A-Rows of this line. A random block for every discarded row
INDEX UNIQUE SCAN / RANGE SCANSingle-row / range lookupIf the A-Rows of a RANGE SCAN is larger than expected, the access condition cannot narrow the range
INDEX FULL SCAN [DESCENDING]The whole index in orderUsed to skip sorting. Very expensive if rows matching the condition come late (Scenario 32)
INDEX FAST FULL SCANThe whole index without orderCovering. The gain is small if the index is as large as the table
NESTED LOOPSLooks up the inner side for every outer rowInner Starts is tens of thousands or more
HASH JOINBuilds a hash table from the Build setBuild is the larger side, or Used-Tmp is present
SORT ORDER BY [STOPKEY]Sort / sort for top N rowsIt is Top-N but the input to the STOPKEY sort is large → can sorting be skipped by index order?
COUNT STOPKEY, WINDOW NOSORT STOPKEYStops at N rowsIt stops early only if what is below produces rows in order without sorting
FILTER (two or more children)Runs a subquery per rowA subquery that was not unnested. Check Starts
VIEWA view that was not mergedThe outer condition cannot go inside, so the whole view is computed

Order to Follow in Practice

  1. Find the operation with the largest Buffers and its own share. Compare tuning effects by Buffers.
  2. Compare that operation's A-Rows with the result row count. If it reads a lot and keeps little, look for a way to apply the condition earlier (as access, lower in the plan).
  3. Find operations with large Starts. See whether the repetition itself can be removed (join method, aggregate then join, subquery transformation).
  4. Compare E-Rows × Starts with A-Rows to find where the optimizer judged wrongly. Decide whether to fix the statistics or to fix it through the statement shape or hints.
  5. For a Top-N statement, check whether there is a stop point (STOPKEY) and whether what is below produces rows in order without sorting.
  6. After the fix, verify that the result is the same (rows, order, values), and compare again with several representative bind values.

Comparison with Other DBMSs

ItemOraclePostgreSQLSQL Server
Actual planDISPLAY_CURSOR … ALLSTATS LASTEXPLAIN (ANALYZE, BUFFERS)Actual execution plan (SET STATISTICS XML ON)
Number of executionsStartsloopsActual Executions
Actual rowsA-Rows (sum)rows (average per run) × loopsActual Rows (sum)
Logical I/OBuffers (blocks)Buffers: shared hit + readActual Logical Reads (pages)
Conditionsaccess / filter in Predicate InformationIndex Cond / Filter, Rows Removed by FilterSeek Predicates / Predicate

In the Articles

NOTE Output formats and Note wording differ slightly by Oracle version. The output in this document is from Oracle 23ai in the sandbox.

Related pages