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.

EasyTechnical
142 practiced
You run EXPLAIN for the query:
EXPLAIN SELECT * FROM orders WHERE customer_id = 123;
The planner reports a Seq Scan on orders despite an index on customer_id. List the possible reasons the optimizer prefers a sequential scan, describe steps and SQL commands you would run to diagnose the cause, and outline fixes you might apply.
HardTechnical
92 practiced
A table contains very wide JSONB columns and queries filter inside JSONB fields. Explain strategies to optimize such queries: expression indexes, creating generated columns, using document stores, or moving to a columnar schema. Discuss trade-offs in flexibility vs performance.
EasyTechnical
140 practiced
You see a query plan with a Nested Loop Join where the inner side is driven by an index scan and the outer table has 1M rows. Explain when a nested loop is appropriate and when you would expect the optimizer to choose hash or merge join instead. What factors determine join algorithm selection?
HardTechnical
78 practiced
A long-running aggregation query reads a large amount of data. Explain trade-offs between computing aggregations on demand, pre-aggregating via ETL jobs, and using materialized aggregates. Include cost models (compute vs storage) and how you'd project break-even points.
HardTechnical
70 practiced
You want to reduce planning time for very complex queries that are re-run often with different parameters but identical structure. Describe caching approaches (prepared statements, stored procedures, plan normalization) and their pros/cons in a high-concurrency environment.

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.