4.4.18 · D3Databases

Worked examples — Concurrency anomalies — dirty read, non-repeatable read, phantom read

4,092 words19 min readBack to topic
Figure — Concurrency anomalies — dirty read, non-repeatable read, phantom read

Before symbols, the vocabulary — all borrowed straight from the parent, nothing new invented:


The scenario matrix

Every case this topic can throw at you is one row here. Read it as: " observes X because did Y at time Z." The last three columns are the verdict — which anomaly, if any. Where a cell needs extra narrative, the numbered example (E-number in column 1) carries it, so the columns stay clean.

# Case class What does Did commit before acts? Same row's value changed ("moved")? Set of matching rows changed? Verdict
C1 Uncommitted value read UPDATE, no commit yet Dirty read
C2 Uncommitted read that "survives" UPDATE, no commit, then COMMIT ✗ then ✓ still a dirty read
C3 Committed re-read moved UPDATE + COMMIT between two reads Non-repeatable read
C4 Committed range grew INSERT + COMMIT into the range Phantom read
C5 Committed range shrank DELETE + COMMIT from the range Phantom read
C6 Range membership via UPDATE UPDATE that moves a row across the predicate ✗ (for the query's set) Phantom read
C7 Degenerate: no overlap writes a different row No anomaly
C8 Limiting: same value written UPDATE to the identical value + COMMIT ✗ (value unchanged) No anomaly
C9 Real-world word problem UPDATE, no commit at read, then ROLLBACK ✗ then ROLLBACK Dirty read → wrong action
C10 Exam twist: aggregate vs row UPDATE that flips an aggregate ✓ on one row Non-repeatable (subtle)
C11 Zero-input degenerate reads an empty set, INSERTs a match ✓ (0 → 1) Phantom read

The worked examples below hit every cell C1–C11.


E1 — Dirty read (cell C1)


E2 — A dirty read that "commits" is still wrong (cell C2)


E3 — Non-repeatable read (cell C3)


E4 — Phantom read via INSERT (cell C4)

Figure — Concurrency anomalies — dirty read, non-repeatable read, phantom read

E5 — Phantom read via DELETE (cell C5)


E6 — Phantom read via UPDATE across the predicate (cell C6)


E7 — Degenerate: no overlap, no anomaly (cell C7)


E8 — Limiting case: same value written (cell C8)


E9 — Real-world word problem (cell C9)


E10 — Exam twist: aggregate that hides a non-repeatable read (cell C10)


E11 — Zero-input degenerate: phantom out of nothing (cell C11)