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
72 practiced
Given tables customers(id PK), orders(id PK, customer_id FK, created_at timestamp, total numeric), and an index on orders(customer_id). A query "SELECT c.id, (SELECT count(*) FROM orders o WHERE o.customer_id = c.id) FROM customers c" runs slowly. Explain why and propose 2 SQL rewrites and one indexing strategy to speed this up for both small and large customer counts.
EasyTechnical
127 practiced
Describe the difference between a correlated subquery and a join. Give an example SQL snippet of each that returns the same result, and explain the typical performance implications and when the optimizer can transform one into the other.
MediumSystem Design
84 practiced
You are planning to partition a large events table by event_date (daily). Describe the schema changes, indexing strategies, query modifications, and migration approach to move 5 years of data to a partitioned layout with minimal downtime. Include how partition pruning impacts execution plans.
HardTechnical
134 practiced
A complex JOIN query performs poorly due to highly skewed join key distribution. Explain three SQL-level or data-level techniques to mitigate skew: key salting, pre-aggregation of dominant keys, and using a broadcast/join hint. Provide pseudo-SQL for one technique.
HardTechnical
70 practiced
A multi-tenant workload shows that generic table statistics lead to bad plans for tenants with skew. Propose detailed mitigation strategies: per-tenant partitioning, filtered statistics, extended stats, or adaptive plans. Explain operational complexities and how to test the chosen approach.

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.