← Lessons

quiz vs the machine

Silver1130

Databases

The Read Phenomena Dirty Nonrepeatable Phantom

Three classic read anomalies define what each isolation level is allowed to prevent.

5 min read · intro · beat Silver to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. What is a phantom read?

2. Which level prevents dirty reads but still allows nonrepeatable reads?

3. Why are phantoms harder to prevent than nonrepeatable reads?