Sub topic 10
Access and Filter Predicates in a Plan
This chapter assumes you can run EXPLAIN PLAN and read the operation column of DBMS_XPLAN.DISPLAY, and that you know how a composite index is ordered by its leading column. It teaches you to read the Predicate Information section of a plan, which shows how much of your WHERE clause narrows the search and how much is checked row by row.
Why the Predicate Information section matters
Two queries can both show INDEX RANGE SCAN in the plan and differ by a factor of a thousand in work. The operation name tells you that an index is used. It does not tell you how much of the index is read. The Predicate Information section at the bottom of the plan tells you that.
Oracle sorts each condition into one of two roles:
- An access predicate defines where the scan starts and stops. For an index, it limits the part of the index that is read.
- A filter predicate is tested against each row or index entry that the scan has already reached. It removes rows but does not shrink the area that is read.
An access predicate reduces the work. A filter predicate only reduces the output.
Reading the section
Run a plan and display it with the default format.
CREATE INDEX orders_cust_ix ON orders (customer_id);
EXPLAIN PLAN FOR
SELECT order_id, order_date
FROM orders
WHERE customer_id = 42
AND status = 'OPEN';
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);The output looks like this. The exact costs, names and row estimates will differ on your system.
---------------------------------------------------------------------------
| Id | Operation | Name | Rows |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 |
|* 1 | TABLE ACCESS BY INDEX ROWID BATCHED| ORDERS | 5 |
|* 2 | INDEX RANGE SCAN | ORDERS_CUST_IX | 40 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("STATUS"='OPEN')
2 - access("CUSTOMER_ID"=42)The asterisk next to an Id means that step has predicates listed below. Read it in three parts:
- Step 2 uses
customer_id = 42as an access predicate. Oracle descends the B-tree to the first matching entry and reads along the leaf blocks until the value changes. - The index holds no
statuscolumn, so Oracle cannot teststatusin the index. It must visit the table for each of the roughly 40 entries. - Step 1 applies
status = 'OPEN'as a filter after each table block is read. Some of those table visits are wasted, because the row is discarded.
The filter on step 1 is a table-level filter. It is the most common kind, and the fix is often to put the column into the index.
DROP INDEX orders_cust_ix;
CREATE INDEX orders_cust_status_ix ON orders (customer_id, status);With this index, both conditions can appear as access predicates on the index step. Oracle then visits the table only for rows that already match both.
Filters inside the index
A filter can also appear on the index step itself. This happens when a column is in the index but cannot narrow the scan, usually because an earlier column is unconstrained or only constrained by a range.
CREATE INDEX orders_cust_status_date_ix
ON orders (customer_id, status, order_date);
EXPLAIN PLAN FOR
SELECT order_id
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);The query skips status, the middle column. Oracle can start the scan using customer_id, but entries for one customer are ordered by status first and by order_date only within each status. The dates you want are scattered across the whole customer range. The plan typically shows:
2 - access("CUSTOMER_ID"=42)
filter("ORDER_DATE">=TO_DATE(' 2026-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"ORDER_DATE"<TO_DATE(' 2026-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))This is better than a table filter, because rejected entries cost no table visit. It is still worse than an access predicate, because Oracle reads every index entry for customer 42 to find the ones in January. If customer 42 has a million orders, you read a million index entries.
Access predicates stop at the first range
The rule for a composite index is that conditions on leading columns narrow the scan only while they are equalities. Consider an index on (a, b, c):
| Predicate on the query | Access predicates | Filter predicates |
|---|---|---|
| `a = 1 AND b = 2 AND c = 3` | a, b, c | none |
| `a = 1 AND b > 2 AND c = 3` | a, b | c |
| `a > 1 AND b = 2` | a | b |
| `a = 1 AND c = 3` | a | c |
| `b = 2` | none, unless a skip scan applies | b |
After a range condition, or after a gap, the remaining columns are no longer in a contiguous region of the index. They can still be tested cheaply within the index, but they cannot limit the scan. This is why column order, covered in a later chapter, decides how much work a query does.
Confirming with actual row counts
The estimated rows in EXPLAIN PLAN are guesses. To see what really happened, run the statement and display the cursor with runtime statistics.
SELECT /*+ GATHER_PLAN_STATISTICS */ order_id
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_CURSOR(format => 'ALLSTATS LAST'));This needs access to the V$ views, and it must run in the same session straight after the query. Compare these columns:
- E-Rows is the optimizer's estimate and A-Rows is the actual count. A large gap points to stale statistics or a skewed column.
- Buffers counts the blocks read by each step. An index step with a high Buffers value and a low A-Rows value is a sign that filters, not access predicates, are doing most of the selecting.
Practical guidance
- Look at the predicate section before you look at the cost. A cheap-looking plan that has everything as a filter is fragile, because it gets slower as data grows.
- A
TABLE ACCESSstep with a large filter is a hint to extend the index so that the filter column is in it. - A filter on an index step is a hint to reorder or extend the columns so that more conditions become access predicates.
- Do not assume that a condition listed under both
accessandfilterfor one step is a mistake. Oracle sometimes reports the same condition in both lists. Judge by Buffers and A-Rows instead. - A function applied to a column, as in earlier chapters, usually moves the condition from access to filter, or removes the index from the plan altogether.
Exercise
An index exists on (customerid, status, orderdate). A query has WHERE customerid = 7 AND status > 'A' AND orderdate = DATE '2026-03-01'. Which conditions are access predicates and which is a filter predicate on the index step? What would you check to see how costly the filter is?
Show answer
customerid = 7 and status > 'A' are access predicates, because the scan can start at customer 7 and read a contiguous range of statuses. orderdate = DATE '2026-03-01' is a filter predicate, because it follows a range condition on status and so cannot narrow the scan. To see the cost, run the query with the GATHERPLANSTATISTICS hint and display it with DBMSXPLAN.DISPLAYCURSOR(format => 'ALLSTATS LAST'). Compare the Buffers and A-Rows values of the index step. Many buffers for few rows means most of the work is spent on entries that the filter rejects.