InnoDB storage: clustered pages, change buffer, adaptive hash, doublewrite
How InnoDB lays rows into a clustered B-tree, which extras it adds to save I/O, and which buffer pool features are InnoDB-only.
More on MySQL and InnoDB
- InnoDB redo, the binlog and the two-phase commit between them
- InnoDB read views, undo purge and the history list
- InnoDB Gap Locks and Next-Key Locks Explained
- A primary key is known before execution starts
- MySQL EXPLAIN Explained: const, ref, range, index, ALL
- MySQL settings that change query speed
- MySQL diagnosis: slow log, optimizer trace, performance schema
Keep learning
Overview
no (set at initialization) Bigger pages suit scans and wide rows, smaller ones point lookups. Cannot change later. One .ibd per table: space is returned to the OS on DROP or TRUNCATE. yes (resized in chunks) The biggest lever on reads. Usually 50 to 75% of RAM on a dedicated server. 8 (1 if the pool is under 1 GB) Splits the pool to reduce mutex contention. Share of the LRU list kept as the old sublist. How long a page must stay in old before a touch promotes it. Protects hot pages from scans. Background threads that write dirty pages from the flush list. innodb_io_capacity / _max Write budget for background flushing. Too low: dirty pages pile up. Too high: flushing steals I/O from reads. all (none from 8.4) Defers secondary index changes for uncached pages. Helps write-heavy tables on slow disks. 25 (% of pool) Cap on pool memory the change buffer may use. ON (OFF from 8.4) Hash shortcuts for hot equality lookups. Can become a contention point under mixed workloads. partly (8.0.30+) Writes each page twice to survive torn writes. OFF only on storage with atomic 16 KB writes. innodb_buffer_pool_dump_at_shutdown / load_at_startup yes / no Saves the list of hot page ids and reloads them after a restart. Share of the most recently used pages written to the dump. chapters · mysql and innodb InnoDB storage: clustered pages, change buffer, adaptive hash, doublewrite The buffer pool and insert chapters explain the ideas. This one names the parts InnoDB actually ships and the settings that steer them.
1. Tablespace, extent, page
With innodb_file_per_table=ON each table gets its own .ibd file. Inside it, each index owns two segments, one for leaf pages and one for the rest. Segments grow one extent (64 pages, 1 MB) at a time, so pages of one index stay close on disk. Records fill a page from the top, the directory grows from the bottom. A search inside a page binary-searches the directory, then walks a short list. A row larger than about half a page (8 KB) has long VARCHAR, TEXT or BLOB values moved to overflow pages, so that at least two rows fit in a page.
2. The clustered index is the table
A secondary index stores the primary key, not a row address. Rows can move during a page split and no secondary index has to change. The price is a second descent for every lookup that needs columns outside the index. AUTO_INCREMENT appends to the rightmost page, so pages end up nearly full and the hot page stays in memory. Random keys such as UUIDv4 split pages all over the tree and touch more pages than fit in cache. If you need UUIDs, store them as BINARY(16) and use a time-ordered variant (UUIDv7, or UUID_TO_BIN(uuid, 1) for v1).
3. Buffer pool: young and old sublists, flush list, page cleaners
A newly read page enters the old sublist at the 3/8 point. It moves to the young head only if it is touched again after innodb_old_blocks_time (1000 ms). A table scan touches each page several times within a few milliseconds, so its pages leave from the old tail. Modified pages also sit on the flush list, ordered by the LSN of their first change. Page cleaner threads write from its oldest end, paced by innodb_io_capacity and adaptive flushing, which keeps the checkpoint moving. Watch Pages made young and not young in SHOW ENGINE INNODB STATUS to see the policy at work.
4. Change buffer and adaptive hash index
The change buffer parks inserts, delete-marks and purges for secondary index pages that are not in memory. It merges them when the page is next read, in the background, or at a slow shutdown. On SSDs and pools that hold the whole working set it buys little, which is why 8.4 turns it off. The adaptive hash index watches which index pages get repeated equality lookups and builds an in-memory hash on key prefixes for them. A hit skips the B-tree descent. It does nothing for ranges, and under heavy mixed writes its latch can become a bottleneck: look for btr_search waits and test with it OFF. The generic B-tree versus hash trade-off is covered separately.
5. Doublewrite and a warm restart
Redo describes changes to a page, so recovery needs a whole page to apply them to. Doublewrite gives it one: each batch of pages is first written and fsynced to the doublewrite file, then written in place. The extra write is sequential and costs a few percent. At shutdown InnoDB writes the space and page numbers of the hottest 25% of the pool to ib_buffer_pool in the data directory. At startup a background thread reads those pages back, so the server is warm in minutes instead of hours. Progress shows in Innodb_buffer_pool_load_status.
Reference: storage settings in MySQL 8.0
Variable, default, whether it can change at runtime, and the trade Default in 8.0 What it trades
Compare: PostgreSQL
PostgreSQL keeps rows in an unordered heap with indexes pointing at tuple addresses, and protects torn pages with full-page images in the WAL instead of doublewrite: see PostgreSQL index types and WAL and checkpoints.
Recap
Tablespace → segments → 1 MB extents → 16 KB pages. Each record carries DB_TRX_ID and DB_ROLL_PTR. The primary key B-tree holds the rows. Secondary indexes hold the primary key, so keep it short and increasing.
More courses
- Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
- Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
- React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
- System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
- NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
- Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
- Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
- AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
- Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
- TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
- CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
- Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
- Docker — What an image is, why layers cache, and how containers find each other on a network.
- Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
- Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
- AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
- Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.