The Three Phenomena
Isolation levels are defined by which of these read anomalies they forbid.
- Dirty read: a transaction reads a row another transaction has changed but not yet committed. If that other transaction aborts, you read a value that never officially existed.
- Nonrepeatable read: a transaction reads the same row twice and gets different values because another committed transaction changed it in between.
- Phantom read: a transaction runs the same query twice and the second run returns new rows that match the condition because another transaction inserted them.
How Levels Map
- Read Uncommitted allows all three.
- Read Committed prevents dirty reads.
- Repeatable Read also prevents nonrepeatable reads.
- Serializable prevents all three including phantoms.
Why the Distinction Matters
Nonrepeatable reads concern a single existing row changing value. Phantoms concern the set of rows a query matches changing as rows appear or disappear. Stopping phantoms is harder because you must lock conditions, not just rows.
Key idea
Dirty, nonrepeatable, and phantom reads are the three anomalies whose prevention defines the standard isolation levels.