Module 4 · Query optimization
Episode 26 From SQL to Relational Algebra
▶ This video is coming to YouTube soon.
Postgres never runs the SQL you wrote. This episode turns a query into relational algebra and animates the rewrites on a tiny copy of the store: predicate and projection pushdown, EXISTS and IN into semi joins, NOT EXISTS into an anti join, why NOT IN can't follow, and views melting into the query. Then real EXPLAIN output proves every one.
Chapters
- 0:00Intro
- 0:14A billion pairs, never built
- 0:40SQL, read literally
- 1:27The operators, and their plan nodes
- 1:59Rewrites that never change the answer
- 2:27Pushing a filter down
- 3:21Only the columns you need
- 3:59EXISTS becomes a semi join
- 4:37NOT EXISTS, and why NOT IN is different
- 5:18A view is pasted in
- 5:50The code: pushing a selection down
- 6:19Proof: the filter runs inside the scan
- 6:55Proof: subqueries and views become joins
- 7:53What you write, what Postgres plans
- 8:20Recap
- 8:49Next: Statistics and Cost Models