Difficulty: Easy
Correct Answer: Incorrect
Explanation:
Introduction / Context:
Subqueries come in two major types: uncorrelated (regular) and correlated. Understanding the distinction is essential for predicting performance and correctness, particularly when filtering, computing derived values, or performing existence checks.
Given Data / Assumptions:
Concept / Approach:
Because correlated subqueries are dependent on the current outer row, they behave like nested loops conceptually: for each outer row, run the inner query. This often increases cost unless indexed properly or transformed by the optimizer. Regular subqueries, in contrast, can be computed once and reused.
Step-by-Step Solution:
Identify whether the subquery references outer query columns.If yes, treat it as correlated; expect row-by-row evaluation unless optimized.Index the correlated predicate columns to reduce repeated work.Consider rewriting as JOIN/EXISTS if it simplifies logic or improves performance.Benchmark both forms; let the optimizer choose the best plan.
Verification / Alternative check:
Explain plans typically show nested-loop-like behavior for correlated subqueries compared to a one-time computation for uncorrelated ones.
Why Other Options Are Wrong:
It is not “the same” for EXISTS or IN specifically—correlation changes evaluation strategy irrespective of the predicate used.
Common Pitfalls:
Assuming identical performance; forgetting indexes on correlated columns; misunderstanding that correlated subqueries return different results if the outer row changes.
Final Answer:
Incorrect
Discussion & Comments