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
65 practiced
Given a slow query where the optimizer chooses a nested loop join but you suspect a hash join would be faster for most parameter values, outline safe experiments you would run to validate this hypothesis in staging, and how you would measure and justify a configuration change or query rewrite in production.
HardTechnical
90 practiced
You plan to create a new index in production to speed a critical query, but past index changes have sometimes caused regressions. Design a safe rollout and rollback plan that minimizes risk: include steps for creating the index non-blocking, validating performance improvements, gradual rollout, monitoring metrics to watch during rollout, and concrete rollback criteria and steps.
HardSystem Design
140 practiced
Design a benchmarking harness to compare two variants of a heavy aggregation query. Include how you will prepare the database (priming cache, vacuum/analyze), what metrics to capture, how to simulate concurrent users, how many iterations to run, and how to ensure the comparison is fair and reproducible over time.
EasyTechnical
92 practiced
Given table schema:
orders(
  order_id int primary key,
  customer_id int,
  amount numeric,
  created_at timestamp
)
Write a SQL query to compute the total amount for customer_id = 123 over the last 30 days and explain what index you would create so this query can be served with minimal I/O. Explain why your index helps and any trade-offs.
HardTechnical
81 practiced
Case study: You have a transactions table with 200M rows. A CFO report runs an aggregation over several columns and currently takes 8–12 minutes. As the data analyst responsible, present a step-by-step plan to diagnose and improve this report to under 30 seconds for interactive use. Include low-risk quick wins, medium-term schema/index changes, and long-term architectural considerations (columnar store, pre-aggregations).

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.