Skip to content
uencoder

Phantom Read

A phantom read is when the same transaction runs the same range query twice and gets different row counts (another transaction inserted/deleted matching rows); an anomaly still present at repeatable read.

Purpose

To understand phantom rows in concurrent range queries and their defenses (next-key locks / SSI).

Mechanism

Transaction A runs SELECT WHERE age>20 twice; transaction B inserts age=25 and commits in between, so A second query returns one more row (a phantom). Defenses: predicate locks, next-key locks (MySQL), SSI (PostgreSQL).

Use cases

  • Concurrency anomaly analysis
  • Range query isolation
  • Locking strategy design

Related tools

References