Module 0 · Orientation

Episode 2 The Memory Hierarchy

8 min · SQL · Postgres

Title card of Episode 2: The Memory Hierarchy

▶ This video is coming to YouTube soon.

From an L1 cache to a disk seek, access times span eight orders of magnitude. This episode rescales them to human time, races sequential reads against scattered ones on a hard disk and an SSD, explains why databases count 8 KB pages, and shows on a real Postgres where random_page_cost = 4 comes from and how changing it flips a plan.

Chapters

  1. 0:00Intro
  2. 0:15The gap every database is built around
  3. 0:31From an L1 cache to across the ocean
  4. 1:19If one nanosecond lasted one second
  5. 1:56The race: in order against scattered
  6. 3:04Reading 1,000 pages, one at a time
  7. 3:35Why databases count pages
  8. 4:16random_page_cost = 4 is a guess about caching
  9. 5:03Proof: pages, prices, a cold read and a warm one
  10. 6:37How databases live with the gap
  11. 7:09Recap
  12. 7:37Next: Files, Pages and Heap Files