Storage Engine Foundations: Pages, Records, and Layout

LESSON

Database Engine Internals and Implementation

002 30 min intermediate

Day 274: Storage Engine Foundations: Pages, Records, and Layout

A storage engine does not really store "rows." It stores bytes inside pages, and the way those bytes are arranged quietly determines read cost, update cost, fragmentation, and recovery complexity.


Today's "Aha!" Moment

The insight: Once data leaves the logical schema and hits disk or durable storage, the engine stops thinking in terms of "table with columns" and starts thinking in terms of:

That physical layout is the hidden reason later topics like indexes, WAL, MVCC, and query execution behave the way they do.

Why this matters: Developers often speak about rows as if they exist directly on disk. But an engine has to answer harder questions:

Those are page-layout problems, not abstract schema problems.

The universal pattern:

Concrete anchor: A customers table may look like simple rows in SQL, but the engine may actually store each row inside an 8 KB page, with a header, null bitmap, variable-length offsets, and a slot directory. A single update to a long text field may no longer fit in the original position, forcing page reorganization or redirection.

How to recognize when this applies:

Common misconceptions:

Real-world examples:

  1. Short fixed-width records: Cheap to pack densely and scan predictably.
  2. Wide or variable-length records: Harder to update in place and more likely to cause fragmentation or overflow handling.

Why This Matters

The problem: Logical data models describe what the data means, but storage engines must decide how it is physically placed. Poor physical layout decisions create hidden costs:

Before:

After:

Real-world impact: This mental model helps explain why engines make trade-offs like slotted pages, indirection, append-friendly structures, or overflow storage. It also prevents hand-wavy explanations of "database performance" that ignore the actual storage substrate.


Learning Objectives

By the end of this session, you will be able to:

  1. Explain why storage engines work in pages rather than logical rows - Understand page size as the basic unit of durable I/O and caching.
  2. Describe how records are physically organized inside pages - Reason about headers, slot directories, fixed vs variable-length fields, and free space.
  3. Evaluate layout trade-offs - Recognize how page organization affects locality, updates, fragmentation, and future index design.

Core Concepts Explained

Concept 1: Pages Are the Real Unit of I/O and Caching

Storage engines do not typically read one row at a time from disk. They read and write in larger chunks called pages.

A page is usually:

Typical sizes might be:

depending on the engine.

Why pages?

Because storage devices and operating systems reward chunked access much more than tiny random byte reads. Also, the engine needs a stable unit for:

So the first deep shift is:

That means all higher-level access costs are downstream of page behavior:

This is also why later lessons on buffer pools and indexes will care so much about locality.

Concept 2: Records Need Layout Metadata, Not Just Payload Bytes

Once a page is loaded, the engine still needs to locate records inside it.

That is why pages usually include some combination of:

One common pattern is the slotted page:

This indirection is valuable because records may move as the page changes.

Why movement matters:

If external code or indexes pointed directly to the byte offset of every record, any compaction would break them. Slot indirection makes layout more flexible.

Records themselves also need internal metadata, such as:

So a "row" on disk is usually:

not a naive concatenation of columns.

This becomes especially important once fields are:

Concept 3: Layout Trade-offs Shape Updates, Fragmentation, and Future Access Paths

Physical layout is always a trade-off.

If records are packed tightly:

If the engine leaves extra space:

Variable-length columns make this harder:

Deletes create another pressure:

This is why layout decisions ripple outward into later database behavior:

So this lesson is not just about "how bytes are arranged." It is the physical base layer under:

Once that clicks, later lessons stop feeling like separate topics. They become consequences of one physical model.


Troubleshooting

Issue: "Why does updating one field sometimes seem much more expensive than expected?"

Why it happens / is confusing: At the logical level it looks like a tiny change.

Clarification / Fix: The updated record may no longer fit in its current physical space. Check whether variable-length growth, page compaction, overflow handling, or page splits are involved.

Issue: "Why do databases care so much about page size?"

Why it happens / is confusing: SQL abstractions hide the page boundary.

Clarification / Fix: Page size affects I/O granularity, cache efficiency, scan behavior, and how many records or index entries fit together physically. It is a foundational design knob, not arbitrary trivia.

Issue: "Why can deletes and updates make performance worse over time even when row count is stable?"

Why it happens / is confusing: The logical table size may look unchanged.

Clarification / Fix: Physical pages may be accumulating holes, overflow chains, or fragmented free space. The engine may need vacuuming, compaction, or page reorganization to recover locality.


Advanced Connections

Connection 1: Pages and Layout <-> B-Tree Indexes

The parallel: The next lesson will show how B-Tree nodes are pages too. Index design is not separate from page layout; it is another use of the same physical storage unit, optimized for navigation rather than row payload.

Real-world case: Leaf entries and internal nodes both live inside pages, so fanout, split behavior, and pointer stability all inherit page-layout constraints.

Connection 2: Pages and Layout <-> WAL and Recovery

The parallel: Later lessons on WAL and crash recovery depend on page-level reasoning. Recovery replays changes against pages, not against abstract rows in the SQL sense.

Real-world case: Correct redo/undo logic requires stable page IDs, change ordering, and careful tracking of how records physically changed inside a page.


Resources

Optional Deepening Resources


Key Insights

  1. Pages are the true storage unit - Engines optimize around page-sized I/O, caching, and recovery, not around abstract logical rows.
  2. Records need metadata and indirection - Variable lengths, deletes, movement, and free-space reuse force structure beyond simple field concatenation.
  3. Physical layout drives future behavior - Indexes, WAL, MVCC, fragmentation, and scan cost all inherit the consequences of page and record organization.

PREVIOUS Data Models for Transactional and Analytical Systems NEXT B-Tree Index Internals and Access Paths

← Back to Database Engine Internals and Implementation

← Back to Learning Hub