Oracle9i SQL Reference Release 2 (9.2) Part Number A96540-02 |
|
|
View PDF |
Subqueries are "nested" when they appear in the WHERE
clause of the parent statement. When Oracle evaluates a statement with a nested subquery, it must evaluate the subquery portion multiple times and may overlook some efficient access paths or joins.
Subquery unnesting unnests and merges the body of the subquery into the body of the statement that contains it, allowing the optimizer to consider them together when evaluating access paths and joins. The optimizer can unnest most subqueries, with some exceptions. Those exceptions include hierarchical subqueries and subqueries that contain a ROWNUM
pseudocolumn, one of the set operators, a nested aggregate function, or a correlated reference to a query block that is not the subquery's immediate outer query block.
Assuming no restrictions exist, the optimizer automatically unnests some (but not all) of the following nested subqueries:
IN
subqueriesIN
and EXISTS
correlated subqueries, as long as they do not contain aggregate functions or a GROUP
BY
clauseYou can enable extended subquery unnesting by instructing the optimizer to unnest additional types of subqueries:
NOT
IN
subquery by specifying the HASH_AJ
or MERGE_AJ
hint in the subquery.UNNEST
hint in the subquery.
See Also:
Chapter 2, "Basic Elements of Oracle SQL" for information on hints |