Sub topic 2
Checking Index Use in an Execution Plan
What an execution plan shows
This chapter assumes you know basic SELECT, WHERE, and ORDER BY syntax, Oracle data types, and how to run SQL in a client such as SQL*Plus or SQL Developer.
An execution plan is Oracle's chosen method for running a SQL statement. It shows the operations Oracle expects to perform, their order, and estimated work. The plan can show whether Oracle uses an index or reads the whole table.
Use EXPLAIN PLAN FOR to create an estimated plan. Then display it with DBMS_XPLAN.DISPLAY:
EXPLAIN PLAN FOR
SELECT order_id, order_date
FROM orders
WHERE customer_id = 42;
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY);A plan might contain operations like these:
| Operation | Meaning |
|---|---|
| `TABLE ACCESS FULL` | Oracle reads the table's blocks to find matching rows. |
| `INDEX RANGE SCAN` | Oracle searches part of an index for matching key values. |
| `TABLE ACCESS BY INDEX ROWID` | Oracle uses row IDs from an index to fetch table rows. |
| `INDEX UNIQUE SCAN` | Oracle finds at most one index entry, usually through a unique equality condition. |
An index scan is not always better. If a query needs a large part of a table, reading the table sequentially can cost less than finding many rows through an index.
Access predicates and filter predicates
The Predicate Information section is especially useful. It shows how each condition is applied.
An access predicate helps Oracle find entries in an index or rows in a table access operation. A filter predicate is checked after rows or index entries have already been found.
For example, with an index on (customer_id, order_date), this query can use both conditions while scanning the index:
EXPLAIN PLAN FOR
SELECT order_id, order_date
FROM orders
WHERE customer_id = 42
AND order_date >= DATE '2026-01-01'
AND order_date < DATE '2026-02-01';
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY(
NULL, NULL, 'BASIC +PREDICATE'
));In the output, conditions marked as access(...) narrow the index scan. Conditions marked as filter(...) remove rows after an operation has produced them. A filter is not automatically bad, but a condition that you expected to drive an index may indicate a mismatched index or a non-index-friendly expression.
The usual flow looks like this:
Check the actual cursor when possible
EXPLAIN PLAN predicts a plan. It does not show what happened during execution. After running a statement, you can inspect the cursor that Oracle used:
SELECT order_id, order_date
FROM orders
WHERE customer_id = 42;
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(
NULL, NULL, 'ALLSTATS LAST'
));ALLSTATS LAST can show estimated rows beside rows actually produced, when the statement collected execution statistics. Large differences between estimates and actual rows can cause poor index choices and often point to stale or inadequate optimizer statistics.
Exercise
Which plan operation indicates that Oracle reads every block of a table, and where can you check whether a condition drove an index scan?
Show answer
TABLE ACCESS FULL indicates a full table read. Check the Predicate Information section for access(...) conditions and compare the plan with the relevant index definition.