Undo Log Explained: Rollback and Old Row Versions
The undo log keeps the old value of every change. It lets a transaction roll back and lets other readers see the version they started with.
In this chapter
The undo log can roll a change back and show an old version
More on Logs, versions and the buffer pool
Keep learning
Overview
chapters · logs, versions and the buffer pool The undo log can roll a change back and show an old version Before a row changes, the engine saves the way back. That one record does two jobs: ROLLBACK follows it backwards, and a reader that needs an older version follows it to rebuild the row.
1. One undo record per change, and rollback walks them back
Every row carries two hidden columns: the writer (id of the last transaction to change it) and an undo pointer. Run the three statements, then ROLLBACK: the undo stack pops newest first. The inverse of each statement Undo record holds Rollback does the key remove the key old values, old writer, old pointer write them back clear the mark Rollback is real work, often as slow as the change. A crashed 100-million-row transaction repeats it at restart, so load in chunks.
2. Insert undo is cheap, update undo lingers
Pick INSERT, tick both boxes, then switch to UPDATE. A snapshot from before an insert never sees the new row, so insert undo is dropped at commit. Update and delete-mark undo hold old values that older snapshots may read, so they wait for cleanup.
3. The undo pointer is also a version chain
Each undo record keeps the previous pointer, so three updates leave a chain. A reader starts at the row and steps back until a version is old enough for its snapshot. The visibility rule itself is in MVCC. Two places an engine can keep old versions Update in place + undo log New version written into the table Current row overwritten in the page apply undo, newest first (slow for big work) mark the transaction aborted (instant) Cleanup cost undo space and long chains dead rows bloat the table and indexes
4. Cleanup, and the transaction that blocks it
A background cleanup (often called purge) frees an undo record once no open snapshot is older than its transaction. It also removes delete-marked rows for good. Toggle the snapshot mode: an idle open transaction holds cleanup back only when it keeps one snapshot for its whole life. When the undo backlog keeps growing ✕ Symptoms backlog in the hundreds of thousands, undo files filling the disk, slower reads on hot rows (long chains) the oldest open transaction, and whether its session is idle ✓ Fix short transactions, commit after read-only work, batch large deletes, time out idle sessions Freed undo space is reused, but the file only shrinks if the engine truncates it. A worked case is in the MVCC purge interview. ⚙ In real engines
Recap
ROLLBACK and crash recovery apply undo newest first. Cleanup stops at the oldest open snapshot, so one forgotten transaction grows the backlog. Next: MVCC, which decides which version in the chain a reader sees.
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.