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 reporting query is built on top of several layers of database views, and the actual expensive work is buried several views deep. How would you expand and analyze nested views to find the real underlying execution plan, rather than optimizing the visible top-level query in the wrong place?
Explain why the optimizer's default per-column statistics can produce badly skewed cardinality estimates when two predicates on separate columns are actually correlated. What are extended (multi-column) statistics, and how would you decide whether creating them actually fixed a bad plan?
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?
An application (or ETL job) issues one query to load a parent record and then a separate query per child row inside a loop, the classic N+1 pattern. Explain how you would detect this at the SQL/log level in a system you did not build, and describe at least two concrete fixes at different layers (application/ORM and database/query).
What is the difference between EXPLAIN and EXPLAIN ANALYZE (or the equivalent in your database of choice)? Explain what information each gives you, when you would rely on EXPLAIN ANALYZE instead of the plan-only form, and any risk of running EXPLAIN ANALYZE against a production system.
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.