Module 3 · Query execution
Episode 22 Joins I: Nested Loops
▶ This video is coming to YouTube soon.
A nested loop join of our orders and customers costs 8,400,651 page reads done naively and 735 done well. This episode animates simple, block and index nested loops, derives their I/O formulas, picks the outer table, and checks every formula against EXPLAIN (ANALYZE, BUFFERS) in Postgres, including its unique-inner shortcut, Materialize and Memoize.
Chapters
- 0:00Intro
- 0:13Same join, very different bills
- 0:30Simple nested loop: the inner, once per row
- 1:22Block nested loop: once per page, or per block
- 2:24Index nested loop: probe, don't scan
- 3:12Which table goes outside?
- 4:00The code: rows, then pages
- 4:25The code: index nested loop
- 4:39Proof: the textbook loop in Postgres
- 5:15Proof: where Postgres beats the textbook
- 5:54Proof: index probes, and Memoize
- 6:30Trade-offs
- 7:05Recap
- 7:34Next: Joins II: Sort-Merge and Hash