Sub topic 8
Reading the Note Section
Assume you know basic SQL and can generate a plan with DBMS_XPLAN.DISPLAY. This chapter explains the Note section that appears below the plan tree.
What the Note section tells you
The Note section contains plan-level information about how Oracle optimized the statement. It can reveal that Oracle used dynamic sampling, a SQL plan baseline, statistics feedback, or an adaptive plan.
A note is context, not a separate operation. It does not add a step to the plan tree. Read it after checking the operations, predicates, and estimated rows.
For example, a plan might end with:
Note
-----
- dynamic sampling used for this statement (level=2)This means Oracle sampled blocks while optimizing the statement because it needed additional information about row distribution. The sample helped estimate cardinalities, which are the predicted row counts.
Common notes include:
| Note | Meaning |
|---|---|
| `dynamic sampling used` | Oracle sampled table blocks during optimization. |
| `statistics feedback used` | Oracle reused execution feedback to improve estimates for a later optimization. |
| `SQL plan baseline ... used` | A stored SQL plan baseline influenced the chosen plan. |
| `this is an adaptive plan` | Oracle may choose between alternative plan branches during execution. |
The exact wording depends on the Oracle release, optimizer settings, and statement history.
Viewing the Note section
TYPICAL is a useful default format because it shows normal plan details and usually includes relevant notes.
EXPLAIN PLAN FOR
SELECT e.last_name, d.department_name
FROM hr.employees e
JOIN hr.departments d
ON d.department_id = e.department_id
WHERE e.salary > 10000;
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY(format => 'TYPICAL'));BASIC is intentionally minimal. It can omit predicates and other sections that help explain the plan. ALL requests the most detailed output, but the result can be long. You can add +NOTE when you want to make the request explicit:
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY(format => 'BASIC +NOTE'));The format modifiers control displayed sections. They do not force Oracle to create a particular plan.
Interpreting notes carefully
A note can explain why a plan looks unusual, but it does not prove that the plan is efficient.
For example, dynamic sampling means Oracle gathered extra information. It does not mean that the resulting estimate is accurate. Compare the estimate with actual rows by using DBMS_XPLAN.DISPLAY_CURSOR and ALLSTATS LAST after executing the statement.
Similarly, an adaptive-plan note means Oracle can use runtime information to choose a branch. Inspect the executed cursor to determine which branch actually ran.
flowchart TD
A[Read the plan Note] --> B{What does it report?}
B -->|Dynamic sampling| C[Check statistics and estimates]
B -->|Statistics feedback| D[Compare later executions]
B -->|Baseline used| E[Inspect accepted baseline]
B -->|Adaptive plan| F[Inspect the executed cursor]
C --> G[Compare estimates with actual rows]
D --> G
E --> G
F --> GA practical reading sequence
- Generate the plan with
TYPICALformat. - Read the
Notesection and record anything unusual. - Check whether the note explains missing or uncertain statistics.
- Execute the statement with runtime statistics enabled when possible.
- Compare
E-RowsandA-Rowsbefore changing indexes, joins, or hints.
Do not add a hint merely to remove an alarming note. First determine whether the note relates to a real performance problem.
Exercise
A plan says “dynamic sampling used for this statement.” Does this prove that Oracle selected a bad plan?
Show answer
No. It says Oracle sampled data during optimization. Check the actual row counts and performance before deciding whether statistics or another change is needed.