phantom read
Repeat a predicate query and observe a changed set of matching rows.
Use this when Two counts inside one transaction disagree after another transaction inserts a matching row.
without the term
“The same filtered count changes inside my transaction after someone else inserts a matching row. Explain and test it.”
with the term · How do you ask a model for phantom read?
Test this predicate for phantom reads with two sessions. Protect the invariant using the database’s actual isolation behavior.
What is phantom read?
A phantom involves the result set of a repeated predicate query changing because another transaction commits a relevant change. Protection differs by isolation implementation; PostgreSQL Repeatable Read prevents phantoms.
Why does phantom read matter when vibe coding?
An agent can lock the current rows and assume no new matching row can appear.
How do you do phantom read?
Coordinate two sessions around the predicate read and competing insert. Check the chosen isolation level, then protect the invariant with constraints or appropriate transaction coordination.
What goes wrong with phantom read?
An empty result locks no ordinary rows. Preventing phantoms alone does not establish serializability.
Sources for this entry
- PostgreSQL: Transaction isolation
Isolation-level behavior in PostgreSQL; snapshot isolation can still allow serialization anomalies.
Sources checked . Source checks do not establish human editorial approval. How we check content.