What is a 'Phantom Read' versus a 'Non-Repeatable Read'? Which isolation level is required to prevent Phantoms?
Last updated
Non-repeatable read: re-reading the same row in one transaction returns a different or missing value because another transaction updated or deleted it.
Phantom read: re-running a query returns a different set of rows because another transaction inserted (or removed) matching rows.
The SQL standard requires
SERIALIZABLEto prevent phantoms, though InnoDB'sREPEATABLE READ(gap locks) and Postgres snapshots already suppress them.
- https://dev.to/abhivyaktii/understanding-read-phenomena-in-databases-50mk
- https://docs.aws.amazon.com/neptune/latest/userguide/transactions-isolation-levels.html
- https://www.softwarejutsu.com/articles/non-repeatable-reads-explained
- https://umartahir93.medium.com/understanding-phantom-reads-in-postgresql-a4b6cc1c8acd
- https://tacnode.io/glossary/isolation-levels
- https://www.postgresql.org/docs/current/transaction-iso.html
- https://www.reddit.com/r/PostgreSQL/comments/1bnlkco/backend_dev_here_please_explain_a_rule_of_thumb/
- https://github.com/acakojic/postgresql-learning/blob/main/transactions/isolation-levels/1_13_postgresql_repeatable_read_transactional_isolation_level.md