Difficulty: Easy
Correct Answer: Correct
Explanation:
Introduction / Context:
Correlated subqueries are a core SQL pattern for existence checks and scalar lookups. Their evaluation model influences performance and indexing strategy.
Given Data / Assumptions:
Concept / Approach:
Conceptually, a correlated subquery is nested: for each outer row, run the inner query using that row’s values. Engines avoid repeated work where possible via rewrites, caching, and indexes, but the logical model remains a per-row evaluation.
Step-by-Step Solution:
Detect correlation by references to outer columns.Ensure selective predicates and supporting indexes on inner tables.Consider EXISTS/NOT EXISTS for semi-join/anti-join semantics.Rewrite to JOINs where clearer or faster; verify with EXPLAIN plans.Measure performance with realistic data distributions.
Verification / Alternative check:
EXPLAIN plans display nested-loop behavior or transformed join operators; both are consistent with per-row semantics.
Why Other Options Are Wrong:
The behavior does not depend on DISTINCT or GROUP BY; correlation itself drives per-row evaluation.
Common Pitfalls:
Missing indexes on correlated predicates; assuming the optimizer will always rewrite to a join.
Final Answer:
Correct
Discussion & Comments