Database Internals · Chapter 1

Durability in Memory-Based Stores / Column- Versus Row-Oriented DBMS / Row-Oriented Data Layout

Chapter 1 · pages 24–27 · 844 words

Building on the earlier distinction between memory- and disk-based DBMSs, this section explains how in-memory stores still achieve durability: since RAM is volatile, they cannot rely on memory alone, so before any operation is considered complete its result must first be written to a sequential write-ahead log on disk. To avoid having to replay an entire log from the beginning after a crash or restart, in-memory stores also periodically maintain a backup copy on disk — a sorted, disk-based structure updated asynchronously and in batches rather than synchronously with every client request. Recovery then means restoring from the backup and replaying only the log entries written after it.

The batching of log application into the backup is called checkpointing. Each time a batch of log records is applied, the backup represents a consistent snapshot as of that point in time, so the older log entries can be safely discarded. Checkpointing keeps recovery fast by limiting how much log has to be replayed, without forcing clients to wait for the backup itself to be updated on every write. The section also stresses that an in-memory database is not simply "a disk database with a big cache": even when disk-backed systems cache everything in memory, they still pay overhead from serialization formats and disk-oriented layouts, and disk-based structures tend to be wide-and-short trees, whereas in-memory systems can use pointer-chasing structures and layout optimizations that make sense only when random access is cheap.

The chapter then turns to a second major classification axis: column-oriented versus row-oriented database systems, which differ in how tables are physically partitioned on disk. A table is made of rows and columns, where a field is a single value at the intersection of a row and column, and a row is the set of field values that logically belong to one record (typically identified by a key). Storing data row-wise groups together all fields of a given row (horizontal partitioning); storing it column-wise groups together all values of a given column across rows (vertical partitioning). Row-oriented systems like MySQL and PostgreSQL represent the traditional relational approach, while MonetDB and C-Store (the ancestor of Vertica) pioneered the open-source column-oriented approach.

Row-oriented layout is described in detail here: it mirrors the tabular view directly, with every row holding the same set of fields (e.g., ID, name, birth date, phone number), and it fits well when applications read or write whole records together, such as filling in a registration form. Because disk access happens in blocks, and a row-oriented layout keeps a row's fields physically adjacent, a single disk block ends up holding data for all of a record's columns — this gives good spatial locality for whole-row access but becomes wasteful when a query only needs one field (like phone numbers) from many rows, since unrelated column data gets paged in unnecessarily.

Exhibits and original pages (3)page 24page 25page 26

Study 7 questions →