Sobes.tech
Junior — Middle

What is the difference between Repeatable Read and Phantom Read isolation levels when working with transactions?

sobes.tech AI

Answer from AI

The Repeatable Read isolation level guarantees that if a set of rows was read within a transaction, a subsequent read of the same rows will return the same data — changes made by other transactions are not visible. However, new rows that match the query condition may appear — this is called the Phantom Read phenomenon.

A Phantom Read is a situation where, during a transaction, repeated execution of a query results in new rows that were not visible during the initial read. The Repeatable Read isolation level does not prevent the appearance of phantom rows.

To prevent Phantom Reads, the Serializable isolation level is required, which provides full transaction isolation by locking not only the rows being modified but also data ranges, preventing the appearance of new rows that match the query condition.

What is the difference between Repeatable Read and… - sobes.tech