InterviewStack.io LogoInterviewStack.io

Query Optimization and Execution Plans Questions

Making queries fast: reading and interpreting execution/explain plans, identifying full scans, spotting SQL anti-patterns, and rewriting queries for better performance. Covers how the planner chooses join order and access methods, and how statistics drive those choices. A core skill for anyone responsible for query performance in production.

EasyTechnical
68 practiced

What is a database query execution plan, and how does the query optimizer generate one? Explain what it means to read a plan, name the most common physical operators you would expect to see, and describe a real situation where understanding the plan changed how you fixed a slow query.

MediumTechnical
84 practiced

A query issues a correlated subquery to compute a per-row value (for example, a running count or a most-recent-record lookup), and it does not scale. Rewrite the pattern into a form the optimizer can execute as a single set operation, and explain why the rewritten version avoids the per-row cost.

MediumTechnical
76 practiced

Write (or describe) how a LATERAL join can replace a correlated subquery when you need, for each row of an outer table, the top result from a related table (for example the most recent event per user, or the top-N per group). Explain why the LATERAL form is usually more optimizer-friendly than the equivalent correlated subquery.

MediumTechnical
87 practiced

A report that used to be correct now returns incorrect counts, and the cause turns out to be NULL values interacting badly with a join or an aggregate (for example a NOT IN against a column that can be NULL). Walk through how you would diagnose a correctness issue like this, not just a performance one, and what SQL patterns you would flag as risky going forward.

MediumTechnical
117 practiced

Compare OFFSET/LIMIT pagination to keyset (seek) pagination for a large result set. Why does OFFSET-based pagination get progressively slower as the offset grows, and what does keyset pagination need (in the data and in the index) to stay fast and to avoid missing or duplicating rows when the underlying data changes between page loads?

Unlock Full Question Bank

Get access to all Query Optimization and Execution Plans interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.