‹ BACK

Phantom reads

Phantom reads

A phantom read occurs when, in the course of a transaction, two identical queries are executed, and the collection of rows returned by the second query is different from the first.
This can occur when range locks are not acquired on performing a SELECT ... WHERE operation.
This anomaly is a special case of Non-repeatable reads when Trans.1 repeats a ranged SELECT ... WHERE query and, between both operations, Trans.2 creates new rows (in the target table) which fulfill that WHERE clause.
Trans.1 Trans.2
SELECT * FROM users
WHERE age BETWEEN 10 AND 30;
INSERT INTO users(id,name,age) 
VALUES ( 3, 'Bob', 27 );
COMMIT;
SELECT * FROM users
WHERE age BETWEEN 10 AND 30;
COMMIT;
phantom-read range-locks non-repeatable-reads transactions isolation

To check your knowledge the following tests are recommended:
Check your sql sql skills.