Sub topic 2
Recognizing access paths
This chapter assumes you can write SQL with joins and WHERE clauses, that you know what a primary key and an index are, and that you can run EXPLAIN PLAN and DBMS_XPLAN.DISPLAY against a schema such as HR.
Access paths
An access path is the method the optimizer chooses to read rows from one table or index. The Operation column shows it.
| Operation | Meaning |
|---|---|
| TABLE ACCESS FULL | Reads every block of the table. Efficient when most rows qualify. |
| INDEX UNIQUE SCAN | Returns at most one row through a unique index. |
| INDEX RANGE SCAN | Reads a contiguous range of index entries. |
| INDEX FULL SCAN | Reads the whole index in order. |
| INDEX FAST FULL SCAN | Reads the whole index in block order, often without sorting. |
| TABLE ACCESS BY INDEX ROWID | Fetches table rows found through an index. |
EXPLAIN PLAN FOR
SELECT last_name FROM hr.employees WHERE employee_id = 100;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY(format => 'BASIC'));Join methods
A join method is the algorithm that combines two row sources. NESTED LOOPS reads each row of the outer source and probes the inner source, which suits small driving sets with an index. HASH JOIN builds a hash table from one input and probes it with the other, which suits large unindexed inputs. MERGE JOIN SORT sorts both inputs on the join key and merges them.
Access and filter predicates
The Predicate Information section lists two kinds of conditions:
access(...)predicates drive the lookup. The engine uses them to locate rows, for example through an index.filter(...)predicates are applied to rows after they are read. They remove rows but do not reduce the blocks read.
A condition can be a filter when no index supports it. Request this section with +PREDICATE in BASIC format, or use TYPICAL, which includes it by default.
Reading the Note section
The Note section reports plan-level facts. Lines such as dynamic statistics used mean the optimizer sampled data at parse time because statistics were missing. A line that names an SQL plan baseline means the optimizer forced a stored plan. Check the Note before you trust the plan shape.
Why EXPLAIN PLAN may not show the real plan
EXPLAIN PLAN estimates a plan without running the statement. It does not peek at bind variable values, so the estimate can differ from the plan used at runtime. Stale statistics, adaptive plans, and sampling also change the result. Use DISPLAY_CURSOR to see what actually ran.
Exercise
Exercise
A plan shows TABLE ACCESS FULL on EMPLOYEES with a filter predicate on salary, even though an index exists on salary. Name one cause.
Show answer
The optimizer estimates that most rows match, or the index is not usable for that predicate, so a full scan costs less.