Query plans for subqueries
The optimizer can change a subquery to a join automatically if the join provides a lower cost.
For example, Partial
SET EXPLAIN output for a flattened subquery sample
output of the SET EXPLAIN ON statement shows that the optimizer changes
the table in the subquery to be the inner table in a join.
For more information about the SET EXPLAIN ON statement, see Report that shows the query plan chosen by the optimizer.
When the optimizer changes a subquery to a join, it can use several
variations of the access plan and the join plan:
- First-row scan
A first-row scan is a variation of a table scan. When the database server finds one match, the table scan halts.
- Skip-duplicate-index scan
The skip-duplicate-index scan is a variation of an index scan. The database server does not scan duplicates.
- Semi join
The semi join is a variation of a nested-loop join. The database server halts the inner-table scan when the first match is found. For more information about a semi join, see Nested-loop join.