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.
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?
What is a covering index, and how does it let the planner satisfy a query using only the index (an index-only scan) instead of also visiting the table? Given a concrete query that selects a small number of columns with a selective WHERE clause, describe the index you would create and why.
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.
You need to explain to a non-technical stakeholder why a proposed index (or a materialized/pre-aggregated table) is worth the write-latency or storage cost it introduces. Lay out the talking points you would use: the benefit in terms they care about, the concrete cost, and how you would validate afterward that it actually helped.
Compare the performance implications of Common Table Expressions (CTEs), inline derived tables, and temporary tables for an intermediate result that is reused within a larger query. In what circumstances does a CTE hurt rather than help, and how would you decide between the three approaches for a specific slow reporting query?
Unlock Full Question Bank
Get access to all Query Optimization and Execution Plans interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.