Unit -4 - part 2
Unit -4 - part 2
UNIT – IV
Slide 1- 1
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe
Schedule
Uncommitted dependency
Incorrect analysis.
Transaction 2
UPDATE accounts SET balance = balance+( balance * 0.005);
We'll summarize their interactions with the DBMS in the following form:
Schedule S:
r1(A), r2(A), w1(A), w2(A), r2(B), w2(B)
If account A starts with $200
If account B starts with $100
We can trace what would happen with Schedule S.
Schedule S is very bad! (At least, it's bad if you're the bank!)
We withdrew $100 from account A,
But somehow the database has recorded that our account now holds $201.
Serial schedule
Our idea is a serial schedule, in which all operations by a transaction are
grouped together.
For our two transactions, • There are only two ways to arrange their operations
to get a serial schedule:
Serial schedule
Problem :
In practice, a serial schedule isn't realistic, because it means we must wait for
one transaction to complete before starting another.
Solution:
We would really prefer to interleave them — but we need to interleave the
transactions so that they work the same as some serial schedule.
Serializable schedule
As an example, consider Schedule T, which has swapped the third and
fourth operations from S:
in Tk .
The set of edges is used to contain all edges Ti ->Tj for which one of the three
conditions holds:
Create a node Ti → Tj if Ti executes write (Q) before Tj executes read (Q).
Create a node Ti → Tj if Ti executes read (Q) before Tj executes write (Q).
Create a node Ti → Tj if Ti executes write (Q) before Tj executes write (Q).
If a precedence graph contains a single edge Ti → Tj, then all the instructions
of Ti are executed before the first instruction of Tj is executed.
Example: Explanation:
Read(A): In T1, no subsequent writes to A, so no new edges
Read(B): In T2, no subsequent writes to B, so no new edges
Read(C): In T3, no subsequent writes to C, so no new edges
Write(B): B is subsequently read by T3, so add edge T2 → T3
Write(C): C is subsequently read by T1, so add edge T3 → T1
Write(A): A is subsequently read by T2, so add edge T1 → T2
Write(A): In T2, no subsequent reads to A, so no new edges
Write(C): In T1, no subsequent reads to C, so no new edges
Write(B): In T3, no subsequent reads to B, so no new edges
T1
T2 T3
The precedence graph for schedule S1 contains a cycle that's why Schedule S1
is non-serializable.
Example: Explanation:
Read(A): In T4,no subsequent writes to A, so no new edges
Read(C): In T4, no subsequent writes to C, so no new edges
Write(A): A is subsequently read by T5, so add edge T4 → T5
Read(B): In T5,no subsequent writes to B, so no new edges
Write(C): C is subsequently read by T6, so add edge T4 → T6
Write(B): A is subsequently read by T6, so add edge T5 → T6
Write(C): In T6, no subsequent reads to C, so no new edges
Write(A): In T5, no subsequent reads to A, so no new edges
Write(B): In T6, no subsequent reads to B, so no new edges
Conflicting operations:
Two operations are said to be conflicting if all conditions satisfy:
They belong to different transaction
Example
Consider the following schedule:
S1: R1(A), W1(A), R2(A), W2(A), R1(B), W1(B), R2(B), W2(B)
Example
Similarly, swapping non-conflicting operations W2(A) and W1(B) in S11,
the schedule becomes
S11: R1(A), W1(A), R1(B), W2(A), R2(A), W1(B), R2(B), W2(B)
Example
T1 T2
Read(A)
Write(A)
Read(B)
Write(B)
Read(A)
Write(A)
Read(B)
Write(B)
View Equivalent
Two schedules S1 and S2 are said to be view equivalent if they satisfy the
following conditions:
1. Initial Read
2. Updated Read
3. Final Write
1. Initial Read
An initial read of both schedules must be the same.
Suppose two schedule S1 and S2.
In schedule S1, if a transaction T1 is reading the data item A, then in S2,
transaction T1 should also read A.
Above two schedules are view equivalent because Initial read operation in S1 is
done by T1 and in S2 it is also done by T1.
2. Updated Read
In schedule S1, if Ti is reading A which is updated by Tj then in S2 also, Ti
should read A which is updated by Tj.
Above two schedules are not view equal because, in S1, T3 is reading A
updated by T2 and in S2, T3 is reading A updated by T1.
3. Final Write
A final write must be the same between both the schedules.
In schedule S1, if a transaction T1 updates A at last then in S2, final writes
operations should also be done by T1.
Above two schedules is view equal because Final write operation in S1 is done
by T3 and in S2, the final write operation is also done by T3.
schedule S1
The first schedule S1 satisfies all three conditions, so we don't need to check
another schedule.
Hence, view equivalent serial schedule is:
T1 → T2 → T3
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 1- 49
Difference between Serial Schedule and Serializable Schedule
Serializable
Serial Schedule
Schedule
Serial schedule are less efficient. Serializable schedule are more efficient.