Part 4 of 5 · 2 min read
Undo: reverting uncommitted changes
Any change whose transaction never committed is reverted, since atomicity forbids a partial result from surviving.
Undo: reverting uncommitted changes
Think of returning to that same construction site. Reverse any change whose permit was still only pending approval, never signed off, at the moment the stoppage happened, restoring that specific spot to how it looked before work began.
In plain words: undo means reverting a logged change, for any log entry belonging to a transaction that had not yet committed at the time of the crash. This directly satisfies the atomicity guarantee from Level 7: a transaction's effects must all happen or none should, so any change from a transaction that never reached commit must be reverted, leaving no partial trace behind. Undo uses the old value recorded in the log entry, covered in Level 4's write-path page, to restore the data page to what it held before the uncommitted transaction touched it.
A worked example. A price update logged but still uncommitted at the moment of a crash is undone during recovery, restoring the data page to its original price using the old value recorded in that log entry.
The key lines. No new SQL; undo, like redo, is an automatic step performed during crash recovery, before normal operation resumes.
Undo
Undo reverts a logged change, using its recorded old value, for any transaction that had not yet committed at the time of a crash, preserving atomicity by leaving no partial trace of an incomplete transaction.
Example: reversing a construction change whose permit was never fully approved, restoring that spot to how it looked before work began, mirrors undo.
Remember this
Redo finishes what was already committed but might not have reached disk; undo reverses what never finished at all. Both depend entirely on the log having been written durably before the crash, which is exactly why write-ahead logging exists in the first place.
Quick notes
- The log must be durable before the data page, so a crash before the page is flushed does not lose the change.
- Redo reapplies a logged change for any transaction that had already committed before the crash.
- Undo reverts a logged change, using its recorded old value, for any transaction that had not yet committed.
- Redo satisfies durability; undo satisfies atomicity, both using the same durable log as their source of truth.
- Both redo and undo run automatically during crash recovery, before the database resumes normal operation.