Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

TRANSACTIONS AND CONCURRENCY CONTROL

Solutions
1. Consider the following schedule:

S1: R1 (A); R1(C); R2 (B); W2 (B); R3 (B); R1 (A); R3(C); W3(C); W1 (A)
S2: R2 (A); R1(C); R2 (B); R3 (B); W2 (B); R1 (A); R3(C); W3(C); W1 (A)

Which of the above schedules is conflict serializable?

(a) S1 only (b) S2 only


(c) Both S1 and S2 only (d) Neither S1 nor S2

Solution: Option (a)

1
In the above precedence graph cycle is present. Therefore S2 is not conflict serializable.

2. Consider the following schedule:


S: r2 (A), r1 (B), w2 (A), r2 (B), r3 (A), w1 (B), w3 (A), w2 (B)

How many minimum number of moves (where a move consisting of changing the position of
one of the operations) are required to convert S into a conflict serializable schedule?

(a) 1 (b) 2
(b) 3 (d) 4

Solution: Option (a)

Precedence graph for the given schedule is:

If W1 (B) is shifted after r1 (B) then the schedule is r2(A), r1(B), w1(B), w2(A), r2(B), r3(A),
w3(A), w2(B),then precedence graph becomes:

2
Now S is serializable schedule.

3. Consider 2 schedules S1 and S2 with same set of transactions and precedence graph of S1 is

same as precedence graph of S2. Which of the following statement is True?

(a) Both S1 and S2 are conflict equal and conflict serializable schedule
(b) Both S1 and S2 are conflict equal but may not conflict serializable schedule
(c) Both S1 and S2 are conflict equal but may not equal schedules
(d) Both S1 and S2 are conflict equal and but may not view equivalent

Solution: Option (b)

Both S1 and S2 are conflict equal but may not conflict serializable schedule.

If either of S1 or S2 is serial schedule then S1 and S2 become conflict serializable schedule


otherwise not.

4. Which of the following schedules are recoverable?

S1: r1(x), r2(z), r1(z), r3(x), r3(y), w1(x), C1, w3(y), C3, r2(y), w2(y), w2(z), C2
S2: r1(x), r2(z), r1(z), r3(x), r3(y), w1(x), w3(y), r2(y), w2(z), w2(y), C1, C2, C3
S3: r1(x), r2(z), r3(x), r1(z), r2(y), r3(y), w1(x), C1, w2(z), w3(y), w2(y), C3, C2

(a) Only S1 (b) Only S1, S3


(c) Only S2, S3 (d) All S1, S2, S3

Solution: Option (b)

We know that in recoverable, if Ti reads a value written by Tj, then Ti must commit after Tj
commits.

In S2: w3(y) is first and r2(y) appears second. Hence, C2 should appear after C3.But here
C3 is appearing after C2. So, S2 is not recoverable. S1 and S3 are recoverable.

3
5. For the given schedule which of the following statement is true?
S: R4(A), R2(A), R3(A), W1(B), W2(C), R4(B), W2(B)

(a) The schedule cannot be serialized


(b) The schedule is equivalent to T3, T4, T1, T2
(c) The schedule is equivalent to T1, T4, T3, T2
(d) The schedule is equivalent to T2, T3, T1, T4

Solution: Option (c)

Refer the video for conflict serializability.

6. Consider the following schedule:


S: r1(A), r2(B), X, w1(C), w2(A)

How many operations (Read/ Write) can be placed in ‘X’ to make ‘S’, not conflict
serializable?

Solution: 3

If the schedule is shown in tabular form, we get

7. Consider the following schedule:


S: r1(A), r2(A), r3(B), w1(A), r2(C), r2(B), w2(B), w1(C)

How many conflict equal serial schedules are possible with the above schedule?

Solution: 1

As we get only one conflict equal serial order

4
LINKED QUESTIONS: Q.8 AND Q.9

Based on a simple relation TA(SID, CID, Stipend) stores TA assignments and stipends. TA’s
are identified by their student ID’s (SID’s). Consider the following, if transaction executed by
2 different clients at approximately the same time.

T1 T2

Step1: UPDATE TA UPDATE TA


SET Stipend= Stipend + 200 SET Stipend= 200
where CID= ‘CS145’ where Stipend > 2000
COMMIT
Step2: UPDATE TA
SET Stipend= Stipend + 200
where CID= ‘CS145’;
COMMIT

Before either transaction starts, there is a tuple (987, ‘CS145’, 1900) in TA.

8. Suppose T1 executes with isolation level READ COMMITTED and T2 executes with isolation
level READ UNCOMMITTED. Which one of the following figures cannot be a possible final
stipend value for TA987?

(a) 2000 (b) 2200


(c) 2300 (d) None of these

Solution: Option (d)

2000 is the result of the execution sequence: T1.step1, T1.step2, T2


2200 is the result of the execution sequence: T1.step1, T2, T1.step2
2300 is the result of the execution sequence: T2, T1.step1,T1.step2

5
9. Now, suppose instead that T1 executes with isolation level. Repeatable Read and T2 executes
with isolation level Read Committed. Which one of the following figures cannot be a possible
value forTA987?

(a) 2000 (b) 2200


(c) 2300 (d) None of these

Solution: Option (b)

2000 and 2300 are still possible, but 2200 is not, because T2 cannot get in between
T1.step1 and T1.step2 to read the uncommitted value written by T1.step1.

COMMON DATA QUESTIONS

10. Consider the following schedules:

S1: R1(A), W1(A), R2(B), R1(B), W1(B), W2(A), R2(C), R1(C)


S2: R2(B), W2(A), R1(A), W1(A), R1(B), W1(B), R2(C), R1(C)
S3: R1(A), W1(A), R2(B), W2(A), R1(B), W1(B), R1(C), R2(C)
S4: R2(B), R1(A), W2(A), W1(A), R1(B), W1(B), R2(C), R1(C)

Which of the above schedule(s) is/are conflict serializable?


(a) S1 and S2 only (b) S2 only
(c) S1 only (d) None of these

Solution: Option (b)

Refer the videos.

11. Which of the following is TRUE with regards to the correct answer for the above question?

(a) S1 is conflict serializable to T1, T2 (b) S2 is conflict serializable to T2, T1


(c) Both (A) and (B) (d) None of these
Solution: Option (b)

Refer the videos

12. Which among the following 2-phase locking protocols is a deadlock free?

(a) Basic 2PL (b) Strict 2PL


(c) Rigorous 2PL (d) Conservative 2PL

6
Solution: Option (d)

Refer the videos.

Given below are some transaction schedules that involve three transactions:
T1-T2-T3

Schedule 1:
T2: Rx, T2: Ry, T1: Wx, T3: Wy, T3: Wz, T1: Rz, T2: Wy
Schedule2:
T2: Rx, T2: Wy, T3: Ry, T3: Wx, T1: Wy, T3: Rx, T1: Ry, T2: Wy
Schedule 3:
T1: Rx, T2: Ry, T3: Wy, T2: Rz, T3: Rz, T1: Wz, T1: Wy, T2: Wy
Schedule 4:
T1: Rx, T3: Wy, T2: Rz, T3: Rz, T1: Wy, T2: Wx, T1: Ry, T2: Wz

13. Which of the given schedule is conflict serializable?

(a) Schedule 1 (b) Schedule 2


(c) Schedule 3 (d) Schedule 4

Solution: Option (d)

Refer the videos.

14. For the conflict serializable schedule found in the previous question, the equivalent serial
schedule possible:

(a) T3- T1- T2 (b) T2- T1- T3


(c) T3- T2- T1 (d) None of these

Solution: Option (a)

Refer the videos.

15. Which of the following is True about the given schedule ‘S’?

T1 T2

7
R(A)
A=A+100
R(A)
A=A*2
W(A)
W(A)
R(B)
B= B/2
W(B)
R(B)
B= B-100
W(B)

(a) It is conflict serializable


(b) It is view serializable but not conflict serializable
(c) It is conflict serializable but not view serializable
(d) It is not serializable

Solution: Option (d)

The given schedule is not serializable, since it is not conflict serializable, not view
serializable.

16. Which among the following schedules is an irrecoverable schedule?

Solution: Option (d)

8
Refer the videos.

17. Suppose a schedule with 2 transactions T1 and T2:

T1 T2
Read(A)
Write(A)
Read(A)
Commit
Read(A)
Abort

The above schedule is:

(a) Cascadeless schedule (b) Recoverable schedule


(c) Irrecoverable schedule (d) None of these

Solution: Option (c)

Refer the videos. As the value of a data is read by transaction who has committed
but thereafter the transaction, which changed the value of data got aborted, so it is
Irrecoverable schedule.

18. There are 2 transactions, T1 with 2 instructions and T2 with 5 instructions. Find the number of
serialand concurrent schedules respectively.

(a) 2, 2 (b) 21, 21


(c) 2, 21 (d) 21, 2

Solution: Option (c)

No. of serial schedules= No. of transactions= 2

5+2 !
No. of concurrent schedules= =21
5! 2!

19. Which of the following statements are true about recoverable and cascadeless schedules?

(P) All cascadeless schedules are also recoverable


(Q) All recoverable schedules are also cascadeless schedules

9
(R) All strict schedules are cascadeless and recoverable
(S) All cascadeless and recoverable schedules are strict schedule

(a) P and R are correct (b) P and S are correct


(c) P, R and S are correct (d) P, Q and S are correct

Solution: Option (a)

10

You might also like