DBMS Serializability
DBMS Serializability
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
Conflict Serializability
• If a schedule S can be transformed into a schedule S´
by a series of swaps of non-conflicting instructions,
we say that S and S´ are conflict equivalent.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
Conflict Serializability
• Schedule 1 can be transformed into Schedule 2, a serial schedule where T2
follows T1, by series of swaps of non-conflicting instructions.
• Therefore Schedule 1 is conflict serializable.
Schedule 1 Schedule 2
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
• Example of a schedule that is not conflict serializable:
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
Testing for Serializability
• Consider some schedule of a set of transactions T1, T2, ..., Tn
• Precedence graph — a direct graph where the vertices are
the transactions (names).
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
How to check for Conflict serializability?
• Consider the schedule
• T1 | R1(X) R1(X)
• T2 | R2(Y) R2(Y) W2(X)
• T3 | W3(Y)
• Step #1 : Check for the conflicting actions.
• Two or more actions are said to be in conflict if:
• 1. The actions belong to different transactions.
2. At least one of the actions is a write operation.
3. The actions access the same object (read or write).
• The following set of actions is conflicting:
• T1:R(X), T2:W(X), T1:R(X)
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
• While the following sets of actions are not:
• T1:R(X), T2:R(Y), T3:R(X)
T1:R(X), T2:W(Y), T3:R(X)
• For our example, we have a conflict on X (T1 reads it and T2 writes it).
We also have a conflict on Y (T2 reads it and T3 writes it).
Initial Graph
• So it has a conflict property but is it serializable?
• Step #2 : Check for a cycle in the Precedence Graph. T1 T2
• First, draw all the Transactions (Tx):
T3
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
• Check if there is a Tx that reads an item after a different Tx writes it.
• We have T1 that reads X after T2 writes it, so draw arrow from T2 -> T1
• Check if there is a Tx that writes an item after a different Tx reads it.
• We have T2 that writes X after T1 reads it, so draw arrow from T1 -> T2
• We also have T3 that writes Y after T2 reads it, so draw arrow from T2 -> T3
• Check if there is a Tx that writes an item after a different TX writes it.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
Final Graph
T1 T2
T3
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
VIEW SERIALIZABILITY
• Consider two schedules S1 and S2, where the same set of
transactions participates in both schedules. The schedules S1
and S2 are said to be view equivalent if three conditions are
met:
• 1. If Ti reads initial value of A in S1, then Ti also reads initial
value of A in S2
• 2. If Ti reads value of A written by Tj in S1, then Ti also reads
value of A written by Tj in S2
• 3. If Ti writes final value of A in S1, then Ti also writes final
value of A in S2
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
• The concept of view equivalence leads to the concept of view
serializability.
• We say that a schedule S is view serializable if it is view
equivalent to a serial schedule.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
View Equivalent Schedule
• Consider two schedules S1 and S2, they are said to be view equivalent if
following conditions are true :
T1 T2 T1 T2
• Initial read must be same.
R(A) W(A)
W(A) R(A)
S1 S2
• S1 : T1 reads A from Database.
S2 : T1 reads A from T2.
∴ S1 ≠ S2.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
• There are two transactions say Ti and Tj, The schedule S1 and S2 are view
equivalent if in schedule S1, Ti reads A that has been updated by Tj, and in
schedule S2, Ti must read A from Tj. i.e. write-read(WR) sequence must be
same between S1 and S2.
T1 T2 T3 T1 T2 T3 S1 : T3 reads value of A from T2.
S2 : T3 reads value of A from T1.
W(A) W(A)
∴ S1 ≠ S2.
W(A) i.e. write-read sequence is not
W(A)
R(A) same between S1 and S2.
R(A)
S1
S2
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
• Final write operations should be same between S1 and S2.
T1 T2 T3
T1 T2 T3
W2(A)
W1(A)
R2(A) W3(A)
W3(A) R2(A)
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
• Check whether the schedule is view serializable or not?
• S : R2(B); R2(A); R1(A); R3(A); W1(B); W2(B); W3(B)
• Solution: With 3 transactions, total number of schedules possible = 3! = 6
• <T1 T2 T3>
• <T1 T3 T2>
• <T2 T3 T1>
• <T2 T1 T3>
• <T3 T1 T2>
• <T3 T2 T1>
• Step 1 : Final Updation (Write) on data items
• A: -
• B : T1 T2 T3
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
• Since the final updation on B is made by T3, so the transaction T3 must execute before transactions T1
and T2.
• Therefore, (T1,T2) → T3
• Now, Removing those schedules in which T3 is not executing at last.
• Remaining Schedules : <T1 T2 T3> and <T2 T1 T3>
• Step 2 : Initial Read + Which transaction updates after read?
• A : T2 T1 T3
• B : T2 T1
• The transaction T2 reads B initially which is updated by T1. So T2 must execute before T1.
• Hence, T2 → T1
• Now, Removing those schedules in which T2 is not executing before T1.
• Remaining Schedules : <T2 T1 T3>
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
• Step 3 : Write Read Sequence (WR) :
• No need to check here.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
• Check whether the schedules is View serializable or not ?
• R2(A); R1(A); W1(C); R3(C); W1(B); R4(B); W3(A); R4(C); W2(D);
R2(B); W4(A); W4(B)
• Solution
• The data items on which operations are occurring are A,B,C,D.
• Step 1 : Check for Final Updation (Write) on data items
• A : T3 T4
• B : T1 T4
• C : T1
• D : T2
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
• Since the final updation on A is made by T4, so the transaction T4 must execute after T3
transaction.
• Since the final updation on B is made by T4, so the transaction T1 must execute before T3
transaction.
• Dependency 1 : (T1 T3) → T4 ..... (1)
• Step 2 : Initial Read
• Initial Read + Which transaction updates after read?
• A : T2 T1 T3
• The transaction T2 and T1 reads A initially from DB which is updated by T3. So T3 must
execute after T1 and T2.
• Dependency 2 : (T2 T1) → T3 ..... (2)
• From (1) and (2) dependencies, another dependency can be concluded as :
• Dependency 3 : (T1 T2) → T3 → T4 ..... (3)
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
• Step 3 : Write Read Sequence (WR) :
WR Seq. : Dependencies :
W1(C) R3(C) T1 → T3
W1(C) R4(C) T1 → T4
W1(B) R4(B) T1 → T4
W1(B) R2(B) T1 → T2
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
• Check whether given schedule is view serializable. Justify your answer.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
References
• Silberschatz A., Korth H., Sudarshan S., "Database System Concepts",
McGraw Hill
THANK YOU !!
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]