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

You are looking at a plan that uses index scans, but the actual execution time is high because the index lookups are producing a lot of random I/O. Explain the conditions under which a single sequential scan can genuinely be faster than many small indexed lookups, and how you would decide which is happening for a specific slow query.

EasyTechnical
69 practiced

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.

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.

HardTechnical
131 practiced

A query (or a whole class of queries) that used to run fine has regressed significantly, seemingly overnight, with no application change. Walk through your triage process for narrowing down what changed: what evidence you would gather first, the handful of underlying causes that pattern is usually explained by, and how you would confirm which one actually happened rather than guessing.

MediumTechnical
117 practiced

Compare OFFSET/LIMIT pagination to keyset (seek) pagination for a large result set. Why does OFFSET-based pagination get progressively slower as the offset grows, and what does keyset pagination need (in the data and in the index) to stay fast and to avoid missing or duplicating rows when the underlying data changes between page loads?

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.