Unit 9 of 12 · about 4 hours · explain, measure

Compression, buffer-pool caching and sequential versus random I/O

Most storage wins come from reading fewer bytes, not faster bytes. Encoding, caching and access pattern decide how many bytes each query moves.

You'll be able to

  • Explain dictionary, run-length and difference encoding and which column shapes each suits.
  • Distinguish buffer-pool hits from misses and state what each costs.
  • Measure sequential versus random read patterns on your machine and explain the gap.

Covers

Compression and encoding trade-offsCaching and buffer-pool behaviorSequential versus random I/O
1

Read

In this order, only the parts listed

0 of 3 done

  1. CMU 15-445 Fall 2025 compression and buffer poolCMU 15-445 - Storage, Index and Recovery Sequence

    Lecture #06: Storage Models and Compression, Section 5 Columnar Compression with run-length, bit-packing, bitmap, difference and dictionary schemes, with Lecture #04: Memory Management for buffer-pool structure and replacement

    Use Lecture #06 for encoding schemes and Lecture #04 for pool mechanics. Leave ARC tuning internals for the project code.

  2. PostgreSQL buffer management and dirty-page flushingThe Internals of PostgreSQL - Buffer Manager, WAL and Recovery

    Chapter 8, Sections 8.4 and 8.6: buffer management mechanisms and dirty-page flushing (page read 2026-10-15)

    Read for clock-sweep behavior and flush timing. Skip Section 8.5 on PostgreSQL 18 asynchronous I/O; it is beyond this unit.

  3. Columnar compression and sequential writesDDIA 2e - Chapter 4 Storage and Retrieval

    Chapter 4, Column-Oriented Storage, printed pp. 136-141 for bitmap encoding, run-length for bitmaps and sorted-column compression, with the sequential-versus-random-writes discussion at printed pp. 129-131

2

Focus on

  • Dictionary encoding suits low-cardinality strings. Run-length suits sorted runs. and frame-of-reference suit timestamps and monotonic IDs. Random UUIDs compress poorly under all of them.
  • A buffer-pool hit serves from memory with no disk I/O. A miss pays the full device read plus possible eviction and write-back of a dirty victim.
  • Sequential access amortizes seek and rotation cost on disks and maximizes prefetch everywhere. Random access pays per-page positioning; NVMe parallelism narrows the gap; your measurement shows how much is left on your machine.
  • The Systems units on I/O access patterns and storage devices and on pages, buffer pools and storage layouts taught the mechanisms. Here the new work is encoding detail and measuring your own hit and pattern costs.
Common mistakes · 3
  • Claiming compression always speeds queries. It saves I/O but costs CPU; incompressible data pays decode overhead for no byte savings.
  • Reading a hot-cache benchmark as device speed. The first cold read after invalidating the page cache is the device number; the rest measure memory.
  • Treating SSD random reads as free. They avoid seek physics but still pay per-request addressing and controller limits.
3

Try it yourself

Closed-book, before checking anything

Compute dictionary savings for 1 million rows over 100 distinct 20-byte strings: a 2,000-byte dictionary plus 1 byte per code is about 1.0 MB against 20 MB raw, roughly 20x. Then measure cached versus cold reads of one 64 MB file on your machine and report both medians and how you made the reads cold, for example os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_DONTNEED) on the file before each cold read.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Which encoding fits a sorted status column with long runs of equal values?Answer

    Run-length encoding: each run becomes one value plus a count. Dictionary alone would repeat the same code for every row of the run.

  2. 2.A working set fits in the buffer pool, then doubles. What changes at the boundary?Answer

    Hits turn into misses with eviction churn. Latency jumps from memory speed to device speed plus the write-back cost of dirty victims.

  3. 3.Why do LSM flushes and compactions favor sequential I/O?Answer

    They write whole sorted files at once instead of scattering page overwrites. Sequential streams reach device bandwidth; scattered overwrites pay positioning per page.

  4. 4.A benchmark reports 5 GB/s reads from a file that fits in RAM. What does it measure?Answer

    Page-cache speed, not the device. Size the file above RAM or drop caches between runs to see device behavior.

5

Practice

  • CMU 15-445 Fall 2025 Project 1: Buffer Pool Manager

    Buffer pool manager tests including the ARC replacer, disk scheduler and page-guard behavior

    Configure with -DCMAKE_CXX_FLAGS="-include cstdint" under GCC 15 and strip the DISABLED_ test prefix to run them.

You're done when

You predict the cheaper access for a new column shape and your cached-versus-cold measurement confirms the mechanism.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 10 more in the section
  • CMU 15-445 - Storage, Index and Recovery SequenceCarnegie Mellon Database Group · primary

    Follow Fall 2025 lectures 3 to 10 and 21 to 22. Do the BusTub projects from tag v20251119-2025fall (https://github.com/cmu-db/bustub/tree/v20251119-2025fall): P1 (ARC replacer, disk scheduler and buffer pool manager) and P2 (B+ tree with a leaf tombstone buffer), with P0 (Count-Min Sketch) as the C++ warm-up. Tests ship with a DISABLED_ prefix to remove, and GCC 15 needs -DCMAKE_CXX_FLAGS="-include cstdint" at configure time. Use the storage and recovery homework for WAL reasoning, and keep C++ scope bounded to storage and recovery.

  • DDIA 2e - Chapter 4 Storage and RetrievalMartin Kleppmann and Chris Riccomini · required

    Read "Storage and Indexing for OLTP" (log-structured storage, B-trees, their comparison and secondary indexes) and "Data Storage for Analytics" (column-oriented storage). Its Bloom filter, tombstone and write-ahead log coverage is brief, so take those from OSTEP and The Internals of PostgreSQL. Build a workload decision table, then connect each claim to a measurement from your small store.

  • The Internals of PostgreSQL - Buffer Manager, WAL and RecoveryHironobu Suzuki · support

    Read Chapter 1 Sections 1.2 to 1.4 (heap pages and tuples), Chapter 8 (buffer manager and dirty-page flushing) and Chapter 9 Sections 9.1 to 9.8 (WAL segments, XLOG records, checkpoints and recovery). Compare each mechanism with your simplified store. The site is revised often, so note the date you read it.

Also in this section

  • Hypothesis - Stateful TestingHypothesis · support

    Use RuleBasedStateMachine with rules, bundles and invariants to drive your store and a dictionary model with the same random operation sequences, and check the machine catches a planted bug before trusting a pass.

  • Building Distributed Systems - The Logger and IndexesBuild Distributed Systems · optional

    Only the first three tasks are free (a write-ahead log, its recovery and log segments). Tasks are graded in the browser after login, so treat a pass as a drill and keep your local harness as the evidence.

  • HLD Handbook - Storage Engines and Data StructuresHLD Handbook · required

    Read Part 0 data structures plus Part 4 storage engines and OLTP versus OLAP. Use its exercises for comparison, while the CMU project and local fault tests remain the implementation evidence.

  • PostgreSQL 18 Documentation - WAL Configuration and InternalsPostgreSQL Global Development Group · support

    Read "WAL Configuration" (checkpoints and the redo point crash recovery starts from), "WAL Internals" and "Reliability" for the official, versioned statement of the write-ahead and durability contract.

  • Operating Systems: Three Easy Pieces - Crash Consistency and Data IntegrityRemzi and Andrea Arpaci-Dusseau · required

    Read Chapter 42 (FSCK and journaling: the crash scenarios, data and metadata journaling and their write order) and Chapter 45 (data integrity: checksums, misdirected and lost writes, scrubbing; https://pages.cs.wisc.edu/~remzi/OSTEP/file-integrity.pdf). Turn each crash scenario into an injection point in your store.

  • ARIES: A Transaction Recovery Method (Mohan et al., 1992)ACM TODS (Stanford course copy) · support

    Read the introduction, the overview and restart processing (analysis, redo by repeating history, undo) and the page LSN rule. The rest is 1992 storage detail beyond this section.

  • Build Your Own RedisBuild Your Own · optional

    Use the persistence and data-structure portions only if a second implementation is needed to cement parsing, indexing or append-log behavior. Do not replace the crash-tested stage artifact with tutorial completion.

  • Replicated Log and Stream Processor - Storage SliceRoadmap-Final · support

    Implement checksummed segments, indexes, acknowledgement states, recovery, retention and atomic metadata changes. Preserve every crash schedule and corrupted artifact needed to reproduce a failure.

  • Apache Parquet File FormatApache Software Foundation · support

    Read the File Format layout (row groups, column chunks, footer metadata) and the Page Index page (ColumnIndex and OffsetIndex with per-page min and max values for page skipping). Use it only for file layout and skipping; it does not cover table metadata or catalogs.

  • Linux man-pages: fsyncLinux man-pages project · support

    Read the DESCRIPTION for what fsync and fdatasync guarantee and the directory-sync requirement for new file names, and the ERRORS section for what an EIO from write-back can refer to.