21.23

Consider the three transactions T1, T2, and T3, and the schedules S1 and S2 given below. Draw the serializability (precedence) graphs for S1 and S2, and state whether each schedule is serializable or not. If a schedule is serializable, write down the equivalent serial schedule(s).

T1: r1 (X); r1 (Z); w1 (X);
T2: r2 (Z); r2 (Y); w2 (Z); w2 (Y);
T3: r3 (X); r3 (Y); w3 (Y);

S1: r1 (X); r2 (Z); r1 (Z); r3 (X); r3 (Y); w1 (X); w3 (Y); r2 (Y); w2 (Z); w2 (Y);
S2: r1 (X); r2 (Z); r3 (X); r1 (Z); r2 (Y); r3 (Y); w1 (X); w2 (Z); w3 (Y); w2 (Y);


        T1, T2, T3
   _______________________
  |  T1   |  T2   |  T3
T |       |       |
I | r1(X) | r2(Z) | r3(X)
M | r1(Z) | r2(Y) | r3(Y)
E | w1(X) | w2(Z) | w3(Y)
  |       | w2(Y) |

        Schedule: S1
   _______________________
  |  T1   |  T2   |  T3
  |       |       |
  | r1(X) |       |
T |       | r2(Z) |
I | r1(Z) |       |
M |       |       | r3(X)
E |       |       | r3(Y)
  | w1(X) |       |
  |       |       | w3(Y)
  |       | r2(Y) |
  |       | w2(Z) |
  |       | w2(Y) |

Summary: Possible conflicts occur when T1 writes to X when T3 is 
still reading X.  However T3 does not write to X so this is ok. 
T3 Then reads and writes to Y before T2 reads and writes to Y so
this is ok as well.  Since T2 reads and writes to Z, it is also ok 
that T1 reads Z but does not write. This schedule is serializable
because there are no cycles. 

        Schedule: S2
   _______________________
  |  T1   |  T2   |  T3
  |       |       |
  | r1(X) |       |
  |       | r2(Z) |
T |       |       | r3(X) 
I | r1(Z) |       | 
M |       | r2(Y) |
E |       |       | r3(Y)
  | w1(X) |       |
  |       | w2(Z) |
  |       | w3(Y) |
  |       | w2(Y) |

Summary: This schedule is non-serializable and contains a major
conflict.  Both T2 and T3 are accessing 'Y' when T3 writes to it.
Therefore when T2 writes to 'Y', the transaction for T3 is lost
and overridden.  

22.25

Apply the timestamp ordering algorithm to the schedules in Figure 21.8(b) and (c), and determine whether the algorithm will allow the execution of the schedules.

B: No, X will have been written by T1 by the time T2 tries to read it.
C: Yes