Phantom reads

A phantom read occurs when, during the course of a transaction, another transaction modifies its result set by adding or deleting rows that belong to its result set. An example of this would be the following:

  • Transaction A queries for all users. 1,000 users are returned but the transaction does not commit.
  • Transaction B adds another user; 1,001 users are now in our database.
  • Transaction A queries for all users for a second time. 1,001 users are now returned. Transaction A now commits.

Under a strict serializable isolation level, transaction B should be blocked from adding the new user until transaction A commits its transaction. This can, of course, cause huge contention in the database and contention in the database and lead to performance degradation, as every update operation needs to wait for reads to commit their transactions. This is why, typically, serializable is rarely used in practice.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset