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
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.

HardTechnical
92 practiced

A query plan shows a nested loop join whose estimated row count for a filter step is orders of magnitude lower than the actual row count, and the query is timing out. Walk through how you would confirm this is a cardinality-estimation problem rather than something else, and what your remediation path would look like from fastest-to-apply to most invasive.

MediumTechnical
91 practiced

Given a short EXPLAIN ANALYZE snippet showing a hash join over two sequential scans with a large row count on one side, identify the single most expensive operator, explain why the planner produced this shape, and propose concrete next steps to validate and fix it.

MediumTechnical
138 practiced

What conditions must be satisfied for an index-only scan to actually happen (rather than an index scan followed by a heap lookup)? Include the role of the visibility map and vacuuming, and describe how you would check, for a specific query and index, whether an index-only scan is actually being used and why not if it isn't.

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.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.