MySQL Redo Log vs Undo Log: Key Differences

This article explores the core architectural differences between MySQL’s redo logs and undo logs within the InnoDB storage engine. While both logs are essential for maintaining database transactions and preventing data corruption, they serve fundamentally opposite purposes. Redo logs ensure durability by preserving write operations during system crashes, whereas undo logs support transaction rollbacks and Multi-Version Concurrency Control (MVCC) by keeping track of previous data states.

What is a Redo Log?

The redo log is a disk-based data structure used during crash recovery to correct data written by incomplete transactions. It enforces the Durability property of ACID (Atomicity, Consistency, Isolation, Durability) transactions.

Architecture and Write Mechanism


What is an Undo Log?

The undo log is a collection of log records associated with a single transaction. It is designed to roll back transactions and support consistent reads, fulfilling the Atomicity and Isolation aspects of ACID.

Architecture and Write Mechanism


Architectural Comparison

To clearly understand how these two log systems compare, we can examine their distinct technical attributes:

Feature Redo Log Undo Log
ACID Property Durability Atomicity and Isolation
Log Type Physical (block-level modifications) Logical (SQL-reversing operations)
Primary Purpose Recovery of committed data after a crash Rollback of active transactions and MVCC reads
Write Pattern Sequential write to circular files Dynamic allocation within undo tablespaces
Data Kept Until Data pages are flushed to disk No active transactions need the history
Operation Type Replays changes forward Reverts changes backward

How Redo and Undo Logs Work Together

When a transaction executes in MySQL, both logs work in tandem to ensure system stability.

For instance, when a row is updated: 1. InnoDB writes the old state of the row to the undo log (to allow rollback or read-consistency). 2. The changes to the data page and the undo log page are written to the redo log (to ensure these modifications survive a crash). 3. The changes are made in the buffer pool. 4. When the transaction commits, the redo log buffer is flushed to disk, guaranteeing the transaction is permanent. 5. If the system crashes before the modified data pages reach the disk, MySQL uses the redo log to reconstruct the state. If a transaction was interrupted and never committed, MySQL uses the undo log to revert those partial changes.