Answer the following questions related to concurrency control and transaction schedules. (solutions)

Consider the following transaction schedule of accesses to Amazon’s inventory database to purchase unspecified copies of a CD, DVD, and book. Assume that the transactions run without the benefit of isolation.

T1 T2
Read (# CDs)  
  Read (# Books)
Write (# CDs - 1)  
Read (# Books)  
Write (# Books - 2)  
  Write (# Books - 1)
  Read (# DVDs)
  Write (# DVDs - 1)

These questions are adapted from CS 40: Database Management Systems at Furman University (Treu 2005).

  1. Explain how this schedule violates the requirement of data consistency (i.e., what data anomaly exists?).

  2. Write a serializable schedule for the two transactions that is not simply serial. Justify that it is serializable and that it fixes the aforementioned data anomaly.

  3. Add explicit locking instructions (using shared and exclusive locks) to the initial schedule. Note that inserting locks may cause some existing operations to be reordered. What is the outcome of the two transactions?

  4. Does the transaction schedule with locking satisfy the requirements of two-phase locking (2PL)?

  5. Create a strict two-phase locking (strict 2PL) schedule for the two transactions.