SQL & Databases
50 SQL Interview Questions Every Data Engineer Must Know — Expert Edition - Part 1
For Staff-level Data Engineers, Analytics Engineers, and Platform Engineers.
If the Basics Edition taught you SQL syntax
and the Advanced Edition taught you SQL patterns,
this Expert Edition teaches you how SQL actually runs.
This is where interviews stop asking “can you write SQL?”
and start asking “do you understand how the engine executes it?”
Query plans.
Cost-based optimizers.
Shuffle vs broadcast.
Lakehouse internals.
Partition pruning.
Metadata-driven execution.
If you can answer these — you’re no longer a SQL user.
You’re a data systems engineer.
⭐ TL;DR — What Makes This “Expert”
You are expected to understand:
- Logical vs physical plans
- Cost-based optimizers (CBO)
- Join strategies & shuffles
- Query plan operators
- Statistics & cardinality estimation
- Adaptive Query Execution (AQE)
- Distributed sorting & aggregation
- Why the same query behaves differently in Spark, Snowflake, BigQuery
This is senior-level SQL thinking.
🔍 Previous in This Series
👉 🎯 50 SQL Interview Questions — Basics Edition
👉 🧠 50 SQL Interview Questions — Advanced Edition (Part 1)
👉 🧠 50 SQL Interview Questions — Advanced Edition (Part 2)
If you’ve reached this blog, you’re already past 90% of candidates.
🧩 Topic Distribution (Expert-Level Focus)

Total: 50 questions
This edition focuses on execution-level SQL
the difference between writing queries and owning data systems.
🧠 50 Expert SQL Questions-Answers
🧩 SECTION A — Query Plans & Execution (12 Qs)
1. What is a query execution plan, Logical query plan and Physical query plan?
Answer:
A query plan is the physical strategy the SQL engine chooses to execute your query.
It defines:
- scan type (table scan, index scan)
- join strategy (broadcast, shuffle, hash, merge)
- aggregation method
- data movement (shuffle / exchange)
SQL ≠ execution.
Plan = reality.
Logical query plan:An abstract representation of what the query should do — projections, filters, joins — without execution details.
Physical query plan:Defines how the query executes: join algorithms, shuffle strategy, scan type, parallelism.
3. Why can the same SQL have multiple physical plans?
Answer:
Optimizers explore multiple execution strategies and choose the cheapest based on cost models.
4. What does EXPLAIN show vs EXPLAIN ANALYZE?
Answer:
EXPLAIN→ estimated planEXPLAIN ANALYZE→ actual execution metrics (rows, time, spills)
5. Why should you never trust estimated row counts blindly?
Answer:
Bad statistics = wrong join order = catastrophic performance.
6. What is a pipeline breaker?
Answer:
An operator that forces materialization (e.g., SORT, GROUP BY), breaking streaming execution.
7. Why is ORDER BY expensive in distributed SQL?
Answer:
Requires a global shuffle + sort, not just local sorting.
8. What is a stage in Spark SQL?
Answer:
A set of transformations that can run without shuffling data.
9. Why does LIMIT sometimes not reduce cost?
Answer:
Because LIMIT is applied after shuffle or aggregation in many plans.
10. What is a broadcast exchange?
Answer:
Small table is sent to all executors to avoid shuffle join.
11. When does broadcast join fail?
Answer:
When table size exceeds broadcast threshold or stats are wrong.
12. Why is reading query plans a senior skill?
Answer:
Because performance problems are solved by understanding execution, not rewriting SQL blindly.
⚙️ SECTION B — Cost-Based Optimizer (CBO) (10 Qs)
13. What is a cost-based optimizer?
Answer:
Chooses plans based on estimated CPU, I/O, memory, and network cost.
14. What inputs does a CBO rely on?
Answer:
- Table statistics
- Column cardinality
- Data distribution
- File metadata
15. What happens when statistics are stale?
Answer:
Wrong join order, wrong join type, massive shuffles.
16. Why do warehouses auto-refresh stats?
Answer:
To prevent optimizer decay as data evolves.
17. What is cardinality estimation?
Answer:
Predicting how many rows flow through each operator.
18. Why is skew deadly for optimizers?
Answer:
Average-based estimates hide hot keys → executor overload.
19. How does Snowflake differ from Spark in optimization?
Answer:
Snowflake is always cost-based, Spark historically relied more on heuristics (now improved with AQE).
20. What is join reordering?
Answer:
Optimizer rearranges join sequence to minimize intermediate result size.
21. Why is filter selectivity critical?
Answer:
Highly selective filters drastically reduce downstream cost.
22. When should you manually hint joins?
Answer:
Only when stats are wrong and verified via execution plans.
🔄 SECTION C — Shuffles, Joins & Exchanges (10 Qs)
23. What is a shuffle in distributed SQL?
Answer:
Redistribution of data across nodes based on key.
24. Why are shuffles expensive?
Answer:
Network I/O + disk spill + synchronization overhead.
25. Difference: shuffle hash join vs sort-merge join?
Answer:
- Hash join → faster, memory-heavy
- Sort-merge → stable, but sorting is costly
26. When does Spark choose sort-merge join?
Answer:
When both tables are large and unsorted.
27. What is skew join handling?
Answer:
Splitting hot keys into multiple partitions.
28. Why does DISTINCT often trigger shuffle?
Answer:
Requires global deduplication.
29. What is exchange operator?
Answer:
Logical representation of data redistribution in plan.
30. Why does GROUP BY scale poorly without partitioning?
Answer:
All rows for a key must land on same executor.
31. How does AQE improve joins?
Answer:
Changes join strategy at runtime using actual metrics.
32. Why does COUNT(*) outperform COUNT(col)?
Answer:
COUNT(*) avoids null checks and column reads.
📊 SECTION D — Adaptive Query Execution (AQE) (8 Qs)
33. What is AQE?
Answer:
Runtime optimization that adjusts plans based on real execution stats.
34. What problems does AQE solve?
Answer:
- Wrong join choice
- Skew
- Over-partitioning
35. Can AQE change join type?
Answer:
Yes — e.g., shuffle join → broadcast join.
36. How does AQE handle skew?
Answer:
Splits skewed partitions dynamically.
37. Why is AQE critical for lakehouse workloads?
Answer:
Data size & distribution are unpredictable.
38. Does AQE eliminate need for good SQL?
Answer:
No — it mitigates mistakes, doesn’t fix bad logic.
39. Is AQE deterministic?
Answer:
No — execution may vary depending on runtime stats.
40. Why must engineers still read plans with AQE enabled?
Answer:
Because runtime decisions still affect cost & latency.
🧠 SECTION E — Distributed Semantics & Traps (10 Qs)
41. Why ORDER BY without LIMIT is dangerous?
Answer:
Forces full global sort.
42. Why is ROW_NUMBER() expensive at scale?
Answer:
Requires ordering within partitions.
43. Why does IN (subquery) scale poorly?
Answer:
Often rewritten as semi-join but may not optimize well.
44. EXISTS vs JOIN — performance difference?
Answer:
EXISTS short-circuits on match; JOIN materializes rows.
45. Why does COUNT(DISTINCT) explode cost?
Answer:
Requires shuffle + stateful aggregation.
46. Why do window functions break pipelining?
Answer:
They need full partition visibility.
47. Why does repartitioning too much hurt performance?
Answer:
Excessive task overhead + scheduler pressure.
48. Why does Spark SQL behave differently from Snowflake?
Answer:
Execution engine, memory model, and optimizer philosophy differ.
49. Why is SQL performance non-linear with data size?
Answer:
Shuffles and joins scale super-linearly.
50. What separates senior DEs from juniors in SQL?
Answer:
Understanding execution, cost, and tradeoffs, not syntax.
🧩 Conclusion — Why This Matters
At expert level:
- SQL is systems engineering
- Performance bugs are architectural
- Fixes come from plans, not StackOverflow
If you can reason about:
✔ execution plans
✔ shuffles
✔ cost models
✔ adaptive optimization
You’re not just interview-ready —
you’re production-ready.
🔥 Next in Series
👉 🧠 50 SQL Interview Questions — Expert Edition (Part 2)
Lakehouse internals, metadata, file pruning, MVCC, compaction, CDC, and transactional semantics.
This is where SQL meets storage engines.
🔔 Follow for More
Follow TheDataForge for high-signal deep dives on Spark, Kafka, Streaming, Lakehouse, and real-world data engineering — no fluff, only engineering truth.
⚡️Let’s connect — I post daily Big Data & Spark insights at DataForgeX on X.
💬 Comment Below:Which expert-level topic should I deep dive next?
• Reading Spark / Snowflake query plans
• Join strategy failures & skew debugging
• Cost-based optimizer internals
• AQE deep dive with real examples
• Lakehouse execution vs warehouse execution
🏷️ Tags
#SQL #DataEngineering #DistributedSystems #QueryOptimization
#SparkSQL #Snowflake #BigQuery #Lakehouse #Interviews #DataForge