SQL-Engineering-Handbook

Senior & Staff Database Engineer Subquery Interview Guide

This guide contains 20 senior and staff-level database engineering interview questions and technical answers focused on subqueries, relational algebra, optimizer internals, 3-valued logic, and query refactoring.


Senior/Staff Technical Interview Questions

Question 1: InitPlan vs SubPlan Execution Mechanics


Question 2: The 3-Valued Logic NOT IN NULL Trap


Question 3: Relational Algebra Semi-Join (⋉) Transformation


Question 4: Projected Scalar Subquery Caching


Question 5: Subquery Unnesting Blockers


Question 6: ANY / ALL vs IN — Are They Interchangeable?


Question 7: Why Prefer NOT EXISTS Over NOT IN in Production Code?


Question 8: Predicate Pushdown Into Derived Tables


Question 9: Materialization vs Inlining for CTEs


Question 10: Diagnosing a Hash Semi-Join Disk Spill


Question 11: Indexing Strategy for Correlated Subquery Join Keys


Question 12: Cross-Engine Semi-Join Strategy Differences


Question 13: Anti-Join NULL Handling — Why NOT EXISTS Is Safe


Question 14: Replacing a Correlated Running-Total Subquery With a Window Function


Question 15: How LIMIT Inside a Subquery Blocks Unnesting


Question 16: How Stale Statistics Break Subquery Plan Choice


Question 17: Parallel Query Execution and Correlated Subqueries


Question 18: Correlated Subqueries in the SELECT List vs the WHERE Clause


Question 19: Safely Migrating Legacy NOT IN Code to NOT EXISTS


Question 20: Diagnosing a Subquery-Driven Outage From Monitoring Alone