🐢SQL Query Optimization
Stop guessing why a query is slow and start reading its plan like a story — see how the planner picks scans, joins, and orders, then take a real production query from minutes to milliseconds by reasoning from the plan, not from superstition.
Phase 1How the Planner Thinks
See how the planner turns your SQL into a physical plan
SQL is a wish — the plan is what actually happens
6 minSQL is a wish — the plan is what actually happens
The planner picks the cheapest plan it can imagine
7 minThe planner picks the cheapest plan it can imagine
The planner is only as smart as its row estimates
7 minThe planner is only as smart as its row estimates
Every plan is a tree of pull-based operators
6 minEvery plan is a tree of pull-based operators
Phase 2Reading EXPLAIN ANALYZE in Anger
Read EXPLAIN ANALYZE on progressively gnarlier real queries
Seq Scan isn't always wrong — sometimes it's the right answer
7 minSeq Scan isn't always wrong — sometimes it's the right answer
Three join algorithms, three different stories
7 minThree join algorithms, three different stories
Filter and Index Cond mean very different things
7 minFilter and Index Cond mean very different things
Sort spills to disk are silent assassins
7 minSort spills to disk are silent assassins
BUFFERS counts are the only honest measure of work
7 minBUFFERS counts are the only honest measure of work
Phase 3Stats, Indexes, and Join Order Together
Connect stats, indexes, and join order to plan decisions
Your CTO says "this query is slow — fix it"
7 minYour CTO says "this query is slow — fix it"
An on-call page during dinner
7 minAn on-call page during dinner
The new index that didn't help
7 minThe new index that didn't help
OFFSET 100,000 LIMIT 20
7 minOFFSET 100,000 LIMIT 20
Phase 4Optimize a Real Slow Query End-to-End
Take a real slow query from minutes to milliseconds
Take one real slow query from minutes to milliseconds
8 minTake one real slow query from minutes to milliseconds
Frequently asked questions
- What's the difference between EXPLAIN and EXPLAIN ANALYZE?
- This is covered in the “SQL Query Optimization” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
- Why is my query slow even though I added an index?
- This is covered in the “SQL Query Optimization” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
- How do I tell if the planner is choosing a bad join order?
- This is covered in the “SQL Query Optimization” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
- What does a high 'rows removed by filter' number mean in a plan?
- This is covered in the “SQL Query Optimization” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
- When should I rewrite a query versus add an index?
- This is covered in the “SQL Query Optimization” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
Related paths
🐍Python Decorators Introduction
Build one mental model for Python decorators that covers closures, argument passing, functools.wraps, and stacking — then ship a working caching or logging decorator from scratch in under 30 lines.
🦀Rust Lifetimes Explained
Stop reading `'a` as line noise and start reading it as scope arithmetic — one failing snippet at a time — until you can thread lifetimes through a small parser or iterator adapter without fighting the borrow checker.
☸️Kubernetes Core Concepts
Stop drowning in 30+ resource types. Build the mental model one primitive at a time -- pods, deployments, services, ingress, config -- then deploy a real app with rolling updates and health checks.
📈Big O Intuition
Stop treating Big O as math you memorized for an interview — build the intuition to spot O(n²) disasters, pick the right data structure without thinking, and rewrite a slow function from O(n²) to O(n) in under five minutes.