[prev] 47 [next]

Exercise 2: Update Anomaly

Consider the following transaction (expressed in pseudo-code):

-- Accounts(id,owner,balance,...)
transfer(src id, dest id, amount int)
{
   -- R(X)
   select balance from Accounts where id = src;
   if (balance >= amount) {
      -- R(X),W(X)
      update Accounts set balance = balance-amount
      where id = src;
      -- R(Y),W(Y)
      update Accounts set balance = balance+amount
      where id = dest;
}  }

If two transfers occur on this account simultaneously,
give a schedule that illustrates the "dirty read" phenomenon.