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

For a large fact table partitioned by a date or key column, explain how partition pruning lets the planner skip entire partitions for a query, and what predicate shapes silently defeat it (a function wrapped around the partition column, a predicate that never mentions the partition key, or a join that doesn't align with partition boundaries). Walk through how you would confirm pruning is or isn't happening for a specific query.

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

Every index you add speeds up some reads and slows down every write to that table. Explain the mechanism (what actually happens on INSERT/UPDATE/DELETE), and describe how you would decide, for a table with a heavy write rate, whether a proposed index is worth that cost.

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

You are handed an EXPLAIN ANALYZE output for a multi-join query. Walk through how you would read it: identify the join order, which joins used which physical algorithm, where the actual and estimated row counts diverge, and how you would form a hypothesis about the biggest single contributor to the slowdown.

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.