Database Basics

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?

  1. AT2 obtains its lock immediately, but T3 must wait
  2. BBoth T2 and T3 must wait
  3. CBoth T2 and T3 obtain their locks immediately
Show answer and explanation

Answer: A. T2 obtains its lock immediately, but T3 must wait

A shared lock is taken when reading data; other transactions can also take shared locks on the same data and read it at the same time, but they cannot take an exclusive lock for writing. An exclusive lock is taken when updating data, and while it is held, other transactions can take neither shared nor exclusive locks. In this example, T1's shared lock and T2's shared lock are compatible, so T2 obtains its lock immediately and can read. T3's exclusive lock is incompatible with T1's shared lock, so T3 must wait until T1 releases its lock (and, since T2 also holds a shared lock, until T2 releases its lock as well). Using locks in this way to prevent interference between concurrently running transactions is called concurrency control.

  • A. Correct. Shared locks are compatible with each other, and an exclusive lock is incompatible with a shared lock.
  • B. Shared locks are compatible with each other, so T2 does not wait.
  • C. An exclusive lock is incompatible with a shared lock, so T3 must wait.
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. Which correctly describes two-phase locking (2PL), used for concurrency control of transactions?
  2. 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?
  3. 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?
  4. There are transactions T1 to T5, and one checkpoint was taken before a failure occurred. T1 started and committed before the checkpoint. T2 and T3 started before the checkpoint; T2 committed after the checkpoint but before the failure, and T3 had not committed at the time of the failure. T4 and T5 started after the checkpoint; T4 committed before the failure, and T5 had not committed. In recovery after the failure, which transactions must be rolled forward using the log?
  5. A B+ tree database index was created on the member_no column of a member table with 1 million rows. Which correctly pairs the effect that can generally be expected with its cost?