INDEX_FFS and covering: not reading the table
If every needed column is in the index, the table need not be read. Look at INDEX_FFS, which reads the whole index instead of the table, and at building a covering query by reducing SELECT * to the needed columns.
SQL
Situation
An operations dashboard shows order counts by status and the time of the last order. There is also a feature that downloads a list of "paid orders since June", and this list actually uses only the order ID and order time. Both queries read the whole table or many blocks.
Tables
| Table | Column | Type | Description |
|---|---|---|---|
ORDERS | ORD_ID | NUMBER | Order ID (PK) |
ORDERS | STATUS | VARCHAR2 | 3 order statuses |
ORDERS | ORD_DT | DATE | Order date and time |
ORDERS | Others | CUST_ID, ORD_NO, AMT |
| Index | Columns |
|---|---|
ORDERS_X2 | STATUS, ORD_DT, ORD_ID |
The ORDERS table is about 14,000 blocks, and ORDERS_X2 is about 8,300 blocks.
① Count by status and last order time
BEFORE · Table FULL SCAN
SELECT /*+ FULL(o) */ status, COUNT(*) AS cnt, MAX(ord_dt) AS last_dt
FROM orders o
GROUP BY status
② List of paid orders since June
**BEFORE · SELECT ***
SELECT o.*
FROM orders o
WHERE o.status = 'PAID'
AND o.ord_dt >= DATE '2025-06-01'
For both queries, check whether the execution plan has TABLE ACCESS and which columns the query uses.
Approach
1. List every column the query uses
List every column in the SELECT, WHERE, GROUP BY, and ORDER BY clauses, and check whether an index contains all of them. If one does, there is no reason to read the table.
2. Check whether the index can serve as a "small table"
① has no condition, so it must read everything anyway. But if the needed columns (STATUS, ORD_DT) are all in the index, it can read the whole smaller index instead of the large table. No order is needed here, so index blocks can be read several at a time in storage order.
3. Ask whether every column is really needed
Because of SELECT * in ②, it visits the table for each row to fetch columns not in the index (AMT, CUST_ID, etc.). Keeping only the columns the screen or file actually uses may let the index alone finish the job.
Explanation
① FULL → INDEX_FFS
AFTER · INDEX_FFS
SELECT /*+ INDEX_FFS(o orders_x2) */ status, COUNT(*) AS cnt, MAX(ord_dt) AS last_dt
FROM orders o
GROUP BY status
Why it got faster
- Before #1 reads the whole table (about 14,000 Buffers).
- After #1 reads the whole index (about 8,300 Buffers) with
INDEX FAST FULL SCAN. Both needed columns are in the index, and the index is smaller than the table. INDEX FAST FULL SCANreads the index in storage order, not key order, several blocks at a time like a FULL SCAN. So the result is not sorted, but it is fast.- With the hint removed, the optimizer chooses this plan (the
FULLhint was blocking it).
② SELECT * → only the needed columns
AFTER · Covering (needed columns only)
SELECT o.ord_id, o.ord_dt
FROM orders o
WHERE o.status = 'PAID'
AND o.ord_dt >= DATE '2025-06-01'
Why it got faster
- Before #2 uses about 1,770 Buffers. It found about 16,600 rows through the index and then read a table block for each row with
TABLE ACCESS BY INDEX ROWID. - After #2 uses about 90 Buffers.
ORD_ID,ORD_DT, andSTATUSare all inORDERS_X2, soINDEX RANGE SCANalone finishes the job.TABLE ACCESSdisappears from the execution plan.
Why this is optimal
- ① aggregates everything without a condition, so any structure must be read in full once. It picked the smallest structure (the index).
- ② reads only the index blocks of the needed range. It must read as many rows as are in the range, so it cannot go lower.
Key points
- Covering index: if every column the query uses is in the index, the table is not read.
SELECT *is the most common cause of breaking coverage. - INDEX FAST FULL SCAN: when everything must be read, it reads an index smaller than the table instead. Sort order is not guaranteed.
- INDEX FULL SCAN (key order, one block at a time) and INDEX FAST FULL SCAN (storage order, several blocks at a time) differ. When no sort is needed, FFS is faster.
- Differences by DB: In PostgreSQL,
Index Only Scanplays the same role; in SQL Server, a covering nonclustered index (INCLUDEcolumns) does. PostgreSQL may still check the table (heap) depending on the visibility map state (Heap Fetches).