Skip to main content
Scenario Article

How It Works: The Internals of Database B+ Tree Indexes

Design Challenge: The Cost of Full Table Scans

Abstract Algorithms•Jun 18, 2026
💡 Executive Summary

Database indexes utilize B+ Trees to minimize slow disk I/O operations.

🎯 System Scenario & Requirements

System Goal

Database indexes utilize B+ Trees to minimize slow disk I/O operations.

Actors & Components

  • Application Workers
  • Volatile Memory Tier
  • Persistent Disk Tier
  • Worker Process
  • In-Memory Cache
  • Primary Database

Functional Requirements

  • TLDR: Database indexes utilize B+ Trees to minimize slow disk I/O operations.
  • By organizing data into balanced, wide node pages and linking leaf nodes sequentially, databases resolve queries in logarithmic time and support fast range scans.
  • Imagine you are running a financial reporting application storing 100 million transaction records in a database table.

Constraints & Assumptions

  • While B+ Trees provide fast reads, they introduce trade-offs for write operations: Write Amplification (Page Splits): When inserting rows in random order, pages fill up quickly and split.
  • Writing a single 100-byte row can force the database to allocate, split, and write multiple 16 KB pages back to disk, causing high disk write amplification.

⚡ Execution Stages & Decision Trace

1

Stage 1 — Core Structure: The B+ Tree Node Hierarchy

Action / Decision:

A B+ Tree is a self-balancing search tree designed to store sorted data.

Component Behavior:

It is a variation of the standard B-Tree, optimized specifically for filesystem blocks and database page layouts.

Observable Output: The tree is organized into three distinct node layers: 1.
Read Full Stage in Deep Dive ↓
📖

Deep Dive

Detailed Architectural Analysis

Scenario context

Database indexes utilize B+ Trees to minimize slow disk I/O operations. By organizing data into balanced, wide node pages and linking leaf nodes sequentially, databases resolve queries in logarithmic time and support fast range scans.


Observable outcome: Root Node: The single entry point at the top of the tree, containing pointers to intermediate child pages.

Stage 2 — Core Mechanics: Lookups, Splits, and Leaf Pointers

  • The B+ Tree maintains balance and search efficiency through three core operations: 1.
  • The Lookup Operation To locate a key, the database starts at the root page.
  • It runs a binary search on the keys stored in the root page to find the child pointer range that covers the target.
  • It follows the pointer to the next internal node page and repeats this process until it reaches a leaf node page, where the actual data resides.

Observable outcome: It follows the pointer to the next internal node page and repeats this process until it reaches a leaf node page, where the actual data resides.

Stage 3 — Architectural Blueprint: Query Traversal Flow

  • To visualize a database search, the sequence diagram below maps the interaction between the query engine, cache buffer pool, and disk blocks during a lookup: This sequence diagram illustrates a typical B+ Tree lookup tr…
  • The Query Engine requests pages sequentially from the Buffer Pool cache.
  • If a page is absent from RAM (cache miss), the Buffer Pool fetches the 16 KB page block from SSD disk storage.
  • The Query Engine performs a fast binary search on each page's keys in memory, repeating this traversal down the hierarchy until it extracts the target record from the destination leaf page.
sequenceDiagram
    participant QE as Query Engine
    participant BP as Buffer Pool (RAM)
    participant Disk as Disk Storage (SSD)

    QE->>BP: Request Root Page 0
    BP-->>QE: Page 0 (Cache Hit)
    Note over QE: Binary search Page 0. Select Child Page 12
    QE->>BP: Request Internal Page 12
    BP->>Disk: Fetch Page 12 (Cache Miss)
    Disk-->>BP: Return Page 12
    BP-->>QE: Page 12
    Note over QE: Binary search Page 12. Select Leaf Page 85
    QE->>BP: Request Leaf Page 85
    BP-->>QE: Page 85 (Cache Hit)
    Note over QE: Extract record matching Key 45

Observable outcome: The Query Engine performs a fast binary search on each page's keys in memory, repeating this traversal down the hierarchy until it extracts the target record from the destination leaf page.

Stage 4 — Deep Dive: Disk I/O Blocks and Node Fan-out

  • Understanding why B+ Trees outperform other trees (like Red-Black trees or AVL trees) on disk requires analyzing how hardware reads data.
  • The Internals of Page Allocations and Row Offsets Operating systems and storage controllers read and write data in fixed-size blocks (typically 4 KB).
  • Databases group these blocks into pages (e.g., 16 KB pages in MySQL InnoDB).
  • When the database reads a single byte from a row, the storage controller must transfer the entire 16 KB page block from disk to the RAM buffer pool.

Observable outcome: When the database reads a single byte from a row, the storage controller must transfer the entire 16 KB page block from disk to the RAM buffer pool.

Stage 5 — Real-World Implementation: MySQL InnoDB and PostgreSQL

  • Most modern relational databases implement B+ Trees as their primary indexing structure.
  • In MySQL's InnoDB storage engine, tables are organized as a clustered index .
  • The leaf nodes of the primary key index do not just hold pointers to rows—they store the actual row data itself.
  • If you query by primary key, the lookup returns the row immediately.

Observable outcome: If you query by primary key, the lookup returns the row immediately.

Stage 6 — Practical Implementation: MySQL InnoDB Page Sizing

  • In MySQL InnoDB, the default page size is 16 KB, which is optimal for most OLTP workloads.
  • However, for systems with massive row widths or specialized high-throughput storage, page sizes can be adjusted to optimize alignment with hardware blocks.
  • If the variable returns 16384 , it indicates a 16 KB page size.
  • To change this, you must configure the database during bootstrap: Setting innodb page size = 32K increases the node fan-out, which can flatten the tree further for massive datasets, but it increases the RAM requirements…
-- View the current InnoDB page size configuration in MySQL
SHOW VARIABLES LIKE 'innodb_page_size';
# MySQL Configuration File (my.cnf)
[mysqld]
innodb_page_size = 32K

Observable outcome: To change this, you must configure the database during bootstrap: Setting innodb page size = 32K increases the node fan-out, which can flatten the tree further for massive datasets, but it increases the RAM requirements…

End-to-end outcome

After working through the stages, you should be able to explain:

  • Avoid these indexing mistakes when scaling database architectures: 1.
  • UUIDs as Primary Keys: Using random UUIDs as primary keys in a clustered index causes inserts to target random leaf pages.
  • Wide Fan-out: B+ Tree nodes match disk blocks, keeping the tree flat (height 3-4) to minimize disk reads.
  • Leaf Linked List: Doubly linked leaf nodes allow fast range scans without traversing parent nodes.

Alternatives considered

Decision Guide: Clustered vs. Non-Clustered Indexes

Use this decision table to guide index design in relational databases.

Failure and degraded modes

Trade-offs and Failure Modes: Write Amplification vs. Search Speed

  • Detection: While B+ Trees provide fast reads, they introduce trade-offs for write operations: Write Amplification (Page Splits): When inserting rows in random order, pages fill up quickly and split.
  • User or operator impact: While B+ Trees provide fast reads, they introduce trade-offs for write operations: Write Amplification (Page Splits): When inserting rows in random order, pages fill up quickly and split.
First article in seriesNext Article →

Share this case study

Discuss architecture trade-offs and lessons with your team.

Share:XLinkedInReddit