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
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
68 practiced

Describe a practical approach for detecting both missing and redundant (or unused) indexes in a production database. Which system views, catalogs, or extensions would you query, and what evidence would make you confident enough to actually drop an index rather than just flag it?

MediumTechnical
84 practiced

Walk through the common physical operators you would see in a query execution plan (sequential scan, index scan, index-only scan, nested loop join, hash join, merge join, sort, aggregate). For each, explain why the optimizer would choose it and what cost trade-off (I/O vs. CPU vs. memory) it represents.

MediumTechnical
129 practiced

You have several tables of very different sizes and selectivities to join for a single query. Walk through how join order and predicate placement interact: which filters should run first, how the optimizer decides whether to trust your ordering or reorder itself, and what you would do if the plan it chooses is measurably worse than the order you expect.

MediumTechnical
130 practiced

Explain how parameterized queries and prepared statements protect against SQL injection and also improve plan reuse. What is the trade-off between reusing one compiled plan across very different parameter values and recompiling for each execution?

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.