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.

MediumTechnical
67 practiced

You run EXPLAIN for a query filtering on a column that has an index, and the planner still shows a sequential scan. Give at least four distinct reasons the planner might legitimately prefer a scan here, and for each, describe how you would check whether that reason applies.

MediumTechnical
73 practiced

A plan shows a merge join. What has to be true for the optimizer to choose a merge join, and when is it actually faster than a hash join or nested loop on large, already-sorted data? What breaks it, and what could you change (indexes, explicit sort) to make it a live option?

MediumTechnical
93 practiced

A query with several OR conditions in its WHERE clause is not using the indexes you expect. What is happening, and what rewrite patterns are available to restore index usage while preserving the exact original logic?

HardTechnical
97 practiced

In a columnar cloud warehouse billed by bytes scanned (BigQuery-style), an unpartitioned query over a multi-terabyte table is expensive even though it returns few rows. Estimate the cost impact of the naive query, then propose changes to the table design and the query itself that would meaningfully reduce bytes scanned, with rough before/after numbers.

MediumTechnical
89 practiced

A GROUP BY (or DISTINCT) query is spilling to disk during the aggregate step and running much slower than its data size would suggest. How would you confirm from the plan that a spill is actually happening, and what are your options for reducing or avoiding it, including the trade-off of raising memory settings versus changing the query or the data model?

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.