Sub topic 13
Covering Indexes and Avoiding Table Access
Assume you know basic SELECT, WHERE, ORDER BY, and composite index syntax. You should also be able to read an execution plan and recognize operations such as INDEX RANGE SCAN and TABLE ACCESS BY INDEX ROWID.
An index is covering when it contains every column that Oracle needs for a query. Those columns include columns used in the search conditions and columns returned by the SELECT list. When an index covers a query, Oracle may answer it from the index alone and avoid visiting the table.
Why table access matters
A normal B-tree index stores indexed values and row locations. An index range scan finds matching row locations, but Oracle usually follows those locations back to the table to retrieve unindexed columns. This extra step is called table access by rowid.
For example, this index does not cover the query because order_total is not stored in it:
CREATE INDEX orders_customer_date_ix
ON orders (customer_id, order_date);
SELECT order_id, order_date, order_total
FROM orders
WHERE customer_id = 42
AND order_date >= DATE '2026-01-01'
AND order_date < DATE '2026-02-01';Oracle can use the index to find matching rows, but it must visit the table for order_id and order_total unless those columns are available elsewhere in the plan.
A covering index could include the required columns:
CREATE INDEX orders_customer_date_total_ix
ON orders (customer_id, order_date, order_id, order_total);
SELECT order_id, order_date, order_total
FROM orders
WHERE customer_id = 42
AND order_date >= DATE '2026-01-01'
AND order_date < DATE '2026-02-01';The query can now use an index-only access path. Depending on the estimated cost, Oracle might choose an INDEX RANGE SCAN or an INDEX FAST FULL SCAN.
Confirming index-only access
Use DBMS_XPLAN rather than assuming that an index is being used:
EXPLAIN PLAN FOR
SELECT order_id, order_date, order_total
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);A plan without TABLE ACCESS BY INDEX ROWID indicates that Oracle does not need to visit the table for this query. The plan must still be checked after statistics, data volume, and bind values change.
The trade-off
Adding columns makes an index wider. A wider index consumes more storage, takes longer to create, and increases the work required for inserts and updates. It can also reduce the number of index entries that fit in each block.
Use covering indexes for important, frequent queries where avoiding table access has a measured benefit. Do not add every selected column to every index.
| Query property | Likely effect |
|---|---|
| All required columns are in the index | Table access may be avoided |
| A selected column is absent | Oracle may visit the table |
| Many rows match | A full table scan may cost less |
| The index has many extra columns | DML and storage costs increase |
Exercise
What plan operation should you look for when checking whether an index-only access path avoided table visits?
Show answer
Check that the plan does not contain TABLE ACCESS BY INDEX ROWID for the query.