Module 1 · Storage

Episode 5 Tuple Layout

8 min · SQL · Postgres

Title card of Episode 5: Tuple Layout

▶ This video is coming to YouTube soon.

Every byte of a Postgres row: the 23-byte header, t_hoff, alignment padding (why column order changes table size by 13%), the null bitmap, 1- and 4-byte varlena headers, and TOAST compression and chunking. A layout simulation predicts each size; pageinspect confirms it.

Chapters

  1. 0:00Intro
  2. 0:16Same columns, fewer pages
  3. 0:3730 bytes of data, 60 bytes of row
  4. 1:28The 23-byte header
  5. 2:08Alignment: column order matters
  6. 2:56A NULL costs a bit, not bytes
  7. 3:38Too big for the page: TOAST
  8. 4:28The code: how long is a row?
  9. 5:08Proof: every byte in pageinspect
  10. 6:33What a value costs
  11. 7:09Recap
  12. 7:40Next: Row vs. Column vs. PAX