Sub topic 7
Access and Filter Predicates
This chapter assumes that you can write basic SELECT statements with joins and WHERE clauses, and that you can run EXPLAIN PLAN and DBMS_XPLAN.DISPLAY. You will learn how Oracle reports the conditions used to find rows and the conditions used to discard rows afterward.
Two ways a predicate affects a plan
A predicate is a condition that evaluates to true or false. For example:
WHERE department_id = 50
AND salary > 10000An access predicate helps an operation locate rows. An index can use department_id = 50 to navigate directly to matching index entries. A filter predicate is checked against rows after the operation has found or produced them.
The same SQL condition can have different roles depending on the chosen plan. A predicate might be an access predicate for an index scan in one plan and a filter predicate for a full table scan in another.
Reading Predicate Information
Generate a plan with predicate details:
EXPLAIN PLAN FOR
SELECT last_name, salary
FROM hr.employees
WHERE department_id = 50
AND salary > 10000;
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY(
format => 'TYPICAL +PREDICATE'
));The output contains a Predicate Information section. Each line begins with an operation ID in parentheses. That ID refers to the operation in the plan tree.
A simplified result might look like this:
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("E"."SALARY">10000)
2 - access("E"."DEPARTMENT_ID"=50)Here, operation 2 uses the department condition to find rows. Operation 1 then applies the salary condition. The exact operation IDs and roles depend on the access path selected by the optimizer.
| Predicate label | Meaning | Typical example |
|---|---|---|
| `access` | Helps locate rows or match rows during an operation | `department_id = 50` |
| `filter` | Tests rows after they are produced | `salary > 10000` |
A filter is not automatically a problem. Every query needs conditions somewhere. It becomes important when a costly operation produces many rows and a filter removes most of them afterward. In that case, Oracle may be doing unnecessary work.
Access predicates and indexes
Suppose an index exists on department_id. Oracle can use the equality condition as an access predicate:
2 - access("E"."DEPARTMENT_ID"=50)The index narrows the search before table blocks are visited. If salary > 10000 is not part of the usable index access, Oracle may apply it as a filter after fetching the table rows.
A predicate can also become less useful when it applies a function to an indexed column:
WHERE UPPER(last_name) = 'KING'A normal index on last_name cannot usually provide the same direct access as a search on the stored column value. Oracle may need a function-based index or may evaluate the expression as a filter.
Join predicates
Join conditions appear in predicate information too. For example:
SELECT e.last_name, d.department_name
FROM hr.employees e
JOIN hr.departments d
ON d.department_id = e.department_id;With nested loops, the join condition may be an access predicate for an index lookup into the second table. With a hash join, Oracle may use the condition to match rows in the hash tables. Always read the predicate together with its operation and join method.
A practical reading method
When reviewing predicates:
- Find the operation ID named in each predicate line.
- Identify which rows that operation receives.
- Decide whether the condition locates rows or only removes them.
- Check whether a large row count is reduced late.
- Compare the estimated and actual rows before changing SQL or indexes.
Exercise
A plan shows TABLE ACCESS FULL followed by filter("E"."SALARY">10000). Does this prove that Oracle ignored an index on salary?
Show answer
No. It proves that this plan scans the table and applies the salary condition as a filter. The index might be absent, unusable, too expensive for the estimated selectivity, or unavailable for another reason. Check the plan's access path, statistics, and available indexes before drawing a conclusion.