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.

HardTechnical
73 practiced

An exact DISTINCT or COUNT(DISTINCT ...) over a massive table is too slow for an interactive use case. What approximate techniques exist for this (and for related aggregates), what accuracy trade-off do they carry, and how would you present that trade-off honestly to a stakeholder who wants a single trustworthy number?

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

Compare nested loop, hash, and sort-merge join algorithms: how each works, its memory and I/O profile, and the conditions under which a cost-based optimizer prefers it. What data properties (sorted input, small build side, high join selectivity) make one algorithm clearly better than the others?

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

Explain what a bitmap index scan is and why a planner might choose it over either a plain index scan or a sequential scan. What predicate shapes make it attractive, and what does 'lossy' bitmap behavior mean for very large row estimates?

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.