## CS245 Summer 2000 Solution Set for Homework 7

### Problem 1

(a) The serial execution [T0, T1] will cause T0 to update B to 1. T1 will read this value of B and will therefore not change A. As a result, we will be left with A = 0 and B = 1, which satisfies the consistency condition A*B = 0. For the serial execution [T1, T0], a similar argument can be used to show that A*B = 0 is true at the end of the execution.

(b) The schedule r0(A); r1(B); r0(B); w0(B); r1(A); w1(A); will result in A = 1 and B = 1, thus violating the consistency condition.

(c) There is no concurrent execution of the two transactions that is serializable. The reason is that the first action of T1, namely r1(B) conflicts with the (potentially) last action of T0 which is w0(B). Similarly, the (potentially) last action of T1, namely w1(A) conflicts with the first action of T0, which is r0(A). Hence, there is no way to interleave the actions of the two transactions without sacrificing serializability.

Common Error : In part (c), many tried to assign some other initial values for A and B (such as A = 1, B = 0) and then came up with a concurrent schedule that preserved A*B = 0. Note that first of all, the definition of serializability is independent of the initial values of the data items as well as the semantics of the transactions. Secondly, the initial values have been explicitly mentioned as A=B=0 in the problem statement.

### Problem 2

(b) The precedence graph consists of the set of arcs

{ (T1 --> T2), (T2 --> T3), (T1 --> T3) }

Since there is no cycle, the schedule is serializable. Also, the only equivalent serial schedule is the given schedule itself. There are no other equivalent serial schedules.

(d) The precedence graph consists of the set of arcs

{ (T1 --> T2), (T2 --> T1) }

Since there is a cycle involving T1 and T2, the schedule is not conflict serializable.

### Problem 3

9.7.1
(b) As we reach the right child of the root, we see that the node is full and the insertion may cause the node to split. Thus we cannot release the exclusive lock on the root yet. Then we are directed to the third leaf (the left most child of [23,31,43]). The leaf is also full so similarly we cannot release the lock on the right child of the root.
We then insert 20 in the leaf, split the leaf, add an entry to the right child of the root and split it as well, and update the root. After we are done, we can release the lock on the root, the lock on its right child and the lock on the leaf.
For a B+ tree, every transaction must start from the root. As long as we are still holding the lock on the root, no other transactions can start. So in this question it is fine too if the locks are released from bottom up after each steps.

(c) As we reach the left child of the root, we see that the node has only the minimum number of keys and a deletion may cause the node to merge with its sibling and change the root. Thus we cannot release the exclusive lock on the root yet. Then we are directed to the first leaf and lock it. We see the leaf will not be too empty if we delete an element from it. We can thus safely release the locks on the root and its left child. After we delete 5 from the leaf, we can release the lock on the first leaf.

### Problem 4

#### (b)

• Validation of T1:
There are no other validated transactions, so there is nothing to check.
• Validation of T3:
T1 is validated but not finished. FIN(T1) > START(T3) so we need to check
RS(T3) ∩ WS(T1) = {C, D} ∩ {A} = {}
FIN(T1) > VAL(T3) so we need to check
WS(T3) ∩ WS(T1) = {D} ∩ {A} = {}
So T3 validates.
• Validation of T2
T1 is validated and is finished. FIN(T1) > START(T2) so we need to check
RS(T2) ∩ WS(T1) = {B, C} ∩ {A} = {}
FIN(T1) > VAL(T2) is wrong so we do not need to check WS(T2) ∩ WS(T1)
T3 is validated but not finished. FIN(T3) > START(T2) so we need to check
RS(T2) ∩ WS(T3) = {B, C} ∩ {D} = {}
FIN(T3) > VAL(T2) so we need to check
WS(T2) ∩ WS(T3) = {A} ∩ {D} = {}
So T2 validates.

#### (c)

• Validation of T1
There are no other validated transactions, so there is nothing to check.
• Validation of T3:
T1 is validated but not finished. FIN(T1) > VAL(T3) so we need to check
WS(T3) ∩ WS(T1) = {D} ∩ {C} = {}
FIN(T1) > START(T3) so we need to check
RS(T3) ∩ WS(T1) = {C, D} ∩ {C} = {C}
Validation of T3 fails. So T3 is rolled back and does not write the value for D.
• Validation of T2:
T1 is validated and is finished. FIN(T1) > VAL(T2) is wrong so we do not need to check WS(T2) ∩ WS(T1)
FIN(T1) > START(T2) so we need to check
RS(T2) ∩ WS(T1) = {B, C} ∩ {C} = {C}
Validation of T2 fails. So T2 is rolled back and does not write the value for C.