Database Basics

Transaction T1 ran SELECT COUNT(*) FROM orders WHERE amount >= 1000 and got 8. Immediately afterwards, T2 inserted an order row with an amount of 2000 and committed. When T1 ran the same SELECT statement again, it got 9. What is this phenomenon?

  1. ANon-repeatable read
  2. BDirty read
  3. CPhantom read
Show answer and explanation

Answer: C. Phantom read

When a search with the same condition is repeated within one transaction and the set of result rows changes because another transaction added (or deleted) matching rows and committed in between, the phenomenon is called a phantom read (or phantom). The name comes from the newly appearing rows being like ghosts (phantoms). A non-repeatable read is when a row already read has a different value (or has disappeared) on rereading, because another transaction updated or deleted it and committed. Locks on existing rows cannot prevent rows that do not yet exist from being added, so preventing phantoms requires mechanisms such as locking the range covered by the search condition. Under the SQL standard, phantoms do not occur at the SERIALIZABLE isolation level. T2 committed, so this is not a dirty read.

  • A. A non-repeatable read is when the value of a row already read changes because of another transaction's update.
  • B. T2 committed, so this is not a dirty read, which reads data before it is committed.
  • C. Correct. Rows added by another transaction newly appear in a search with the same condition.
Practice this topic Back to topic

Related calculators

Books on Database Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Database Basics questions

  1. Among the isolation levels defined by the SQL standard, which correctly lists the phenomena that can occur under READ COMMITTED?
  2. Transaction T1 holds a shared lock on a row and is reading it. T2 requests a shared lock and T3 requests an exclusive lock on the same row. Which is correct for the period until T1 releases its lock?
  3. Which correctly describes two-phase locking (2PL), used for concurrency control of transactions?
  4. Transaction T1 took an exclusive lock on row A and then requested a lock on row B, while T2 took an exclusive lock on row B and then requested a lock on row A, so neither can proceed. What does a DBMS typically do when it detects this situation?
  5. When updating data, many DBMSs record the changes in a log (journal) and write that log to nonvolatile storage before the database itself (WAL: write-ahead logging). What is the main reason for this approach?