InterviewStack.io LogoInterviewStack.io

Query Optimization and Execution Plans Questions

Focuses on diagnosing slow queries and reducing execution cost through analysis of query execution plans and systematic query rewrites. Candidates should be able to read and interpret explain output and execution plans including identifying expensive operators such as sequential table scans index scans sorts nested loop join hash join and merge join and explaining why those operators appear. Core skills include cost and cardinality estimation understanding join order and predicate placement predicate pushdown and selectivity reasoning comparing exists versus in versus join patterns and identifying common anti patterns such as N plus one queries. The topic covers profiling and benchmarking approaches using explain analyze and runtime statistics comparing estimated and actual row counts proposing and validating query rewrites and configuration or schema changes and reasoning about trade offs when using materialized views caching denormalization or partitioning to improve performance. Candidates should present step by step approaches to diagnose problems measure improvements and assess impact on other workloads.

MediumTechnical
137 practiced
A query sorts on a computed expression like lower(email) and the plan shows a Seq Scan + Sort. Propose an index-based solution and provide the DDL for creating a functional index to support such queries. Also mention limitations and when the index will not be used.
MediumTechnical
83 practiced
Your team sees intermittent slow queries tied to autovacuum lag causing visibility map issues and preventing index-only scans. Explain how autovacuum, vacuum, and visibility map interact, and propose a tuning plan to restore index-only scan opportunities without starving autovacuum.
EasyTechnical
71 practiced
Define selectivity. Explain with an example why a highly selective predicate is more likely to use an index and how combined predicate selectivity should affect join order choices in the optimizer.
HardSystem Design
117 practiced
Design a safe production rollout plan for creating a large index on a high-traffic table without blocking writes. Include steps such as concurrently building the index, monitoring write/replication metrics, staged rollout, fallback, and deciding when to drop the index if it hurts performance.
MediumSystem Design
94 practiced
Compare materialized views, denormalized tables, and caching for a nightly dashboard that aggregates data from a 1TB events table. For each option, list operational complexity, freshness/consistency guarantees, storage cost, and typical query latency you would expect. Which would you choose if dashboards must be updated within 5 minutes of new events?

Unlock Full Question Bank

Get access to hundreds of Query Optimization and Execution Plans interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.