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
| Item | Description |
|---|---|
| Expected plan | EXPLAIN PLAN FOR … + DBMS_XPLAN.DISPLAY. Does not execute. It does not see bind values, so it can differ from the actual plan |
| Actual plan | DBMS_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 statistics | A session with STATISTICS_LEVEL = ALL, or /*+ GATHER_PLAN_STATISTICS */ in the statement |
| Long statements | SQL 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 statistics | 10046 event trace + TKPROF. For each Parse, Execute, and Fetch: count, cpu, elapsed, disk, query, current, rows |
| Session statistics | SQL*Plus SET AUTOTRACE. The difference before and after execution in consistent gets, physical reads, sorts, etc. |
| Sandbox | Runs 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).
| call | Meaning | What to look at |
|---|---|---|
| Parse | Statement parsing and plan generation | If cpu is large relative to count, it is a hard parse. Misses in library cache during parse: 1 means a hard parse |
| Execute | Execution. DML makes its changes here | Usually small for SELECT. Can be large for plans that must finish a sort or hash before the first Fetch |
| Fetch | Delivering result rows | Most of the work for SELECT. count is the number of round trips (rows ÷ array size) |
Columns disk / query / current | Physical reads / consistent mode reads / current mode reads | query + current is the logical I/O. For SELECT, current is usually 0 |
cpu vs elapsed | CPU time / elapsed time | The 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 withCUSTOMERS(Id 3). - Exception: scalar subqueries in the
SELECTlist andFILTERsubqueries 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
| Column | Meaning | How to read it |
|---|---|---|
| Starts | Number of times the operation ran | For 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-Rows | Expected rows per run | When comparing, compare E-Rows × Starts with A-Rows |
| A-Rows | Sum of actual rows over all runs | If an A-Rows far larger than the result sits in the middle, rows are read and discarded there |
| Buffers | Logical I/O (blocks). Cumulative, including children | Own share = own value − sum of children's values. In the example above, the hash join's own share is 0 |
| Reads | Disk reads. Cumulative | Large only on the first run, usually 0 on the second. Compare using the second run |
| OMem / 1Mem / Used-Mem | Optimal (memory only) / one-pass / actual work memory | The 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. TheORD_DTcondition in the example above was used only as a filter in the full scan, because there is no index that starts withORD_DT.- If
INTERNAL_FUNCTION,TO_CHAR(…), orTO_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 see | Meaning |
|---|---|
this is an adaptive plan | A 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 used | Statistics were missing or insufficient, so sampling happened right before execution |
statistics feedback used | A plan whose estimates were corrected with the A-Rows of a previous execution |
SQL plan baseline … used / SQL profile … used | A stored plan or profile was applied. Check this if the plan does not change after you edit hints |
VW_SQ_n, VW_NSO_n | A view that turned a subquery into a join (Unnesting) |
VW_SSQ_n | A view that turned a scalar subquery into a join |
VW_ORE_n, CONCATENATION | The OR condition was split into branches (OR Expansion) |
VW_JF_SET$…, JOIN FILTER | Bloom filter, join factorization |
VIEW PUSHED PREDICATE | A 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.
| Operation | Meaning | When to suspect |
|---|---|---|
TABLE ACCESS FULL | Reads 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 gave | Index A-Rows ≫ A-Rows of this line. A random block for every discarded row |
INDEX UNIQUE SCAN / RANGE SCAN | Single-row / range lookup | If 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 order | Used to skip sorting. Very expensive if rows matching the condition come late (Scenario 32) |
INDEX FAST FULL SCAN | The whole index without order | Covering. The gain is small if the index is as large as the table |
NESTED LOOPS | Looks up the inner side for every outer row | Inner Starts is tens of thousands or more |
HASH JOIN | Builds a hash table from the Build set | Build is the larger side, or Used-Tmp is present |
SORT ORDER BY [STOPKEY] | Sort / sort for top N rows | It is Top-N but the input to the STOPKEY sort is large → can sorting be skipped by index order? |
COUNT STOPKEY, WINDOW NOSORT STOPKEY | Stops at N rows | It stops early only if what is below produces rows in order without sorting |
FILTER (two or more children) | Runs a subquery per row | A subquery that was not unnested. Check Starts |
VIEW | A view that was not merged | The outer condition cannot go inside, so the whole view is computed |
Order to Follow in Practice
- Find the operation with the largest Buffers and its own share. Compare tuning effects by Buffers.
- 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).
- Find operations with large Starts. See whether the repetition itself can be removed (join method, aggregate then join, subquery transformation).
- 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.
- For a Top-N statement, check whether there is a stop point (
STOPKEY) and whether what is below produces rows in order without sorting. - 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
| Item | Oracle | PostgreSQL | SQL Server |
|---|---|---|---|
| Actual plan | DISPLAY_CURSOR … ALLSTATS LAST | EXPLAIN (ANALYZE, BUFFERS) | Actual execution plan (SET STATISTICS XML ON) |
| Number of executions | Starts | loops | Actual Executions |
| Actual rows | A-Rows (sum) | rows (average per run) × loops | Actual Rows (sum) |
| Logical I/O | Buffers (blocks) | Buffers: shared hit + read | Actual Logical Reads (pages) |
| Conditions | access / filter in Predicate Information | Index Cond / Filter, Rows Removed by Filter | Seek Predicates / Predicate |
In the Articles
- Every Before/After in the sandbox Tuning Scenarios compares execution plans in the order of this document. The Practical Tuning Case follows this order as is on a 13-table plan.
NOTE Output formats and Note wording differ slightly by Oracle version. The output in this document is from Oracle 23ai in the sandbox.