DBMS Transaction
DBMS Transaction
DBMS Transaction
Engineering
College
Database Management System
2
Topics to be covered
What is Transaction
Problems in Transaction
ACID property of Transaction
Transaction States
Concurrency in Transactions
Problems in Concurrent Transaction
Schedule ( Serial & Concurrent)
Serializability
What is Transaction
Transaction Concept
Transaction Concept
A transaction is a unit of program execution that accesses and
possibly updates various data items
A transaction is a logical unit of work that contains one or more
SQL statements. The effects of all the SQL statements in a
transaction can be either all committed or all rolled back
1.Atomicity: The database system keeps track of the old values of any data on
which a transaction performs a write, and if the transaction does not complete
its execution, the database system restores the old values to make it appear as
though the transaction never executed
• Ensuring atomicity is the responsibility of the database system itself. It is
handled by the transaction management component
ACID Properties...
T1 T2
Read(A);
A:=A-100;
Read(A);
Temp=0.2*A;
A:=A-Temp;
Write(A);
Write(A);
Read(B);
B:=B+100;
Write(B);
Need of Concurrency
Control...
T1 T2
Read(A);
A:=A-100;
Write(A);
Read(A);
Temp=0.2*A;
A:=A-Temp;
Write(A);
Read(B);
B:=B+100;
Need of Concurrency 13
Control...
Unrepeatable Read Problem
It happens when two or more
different values of the same data
are Read during the read operation
in the same transaction.
T1 T2
sum=0;
Read(A);
A:=A-100;
Write(A);
Read(A);
sum:=sum+A;
Read(B);
sum:=sum+B;
Read(B);
B:=B+100;
Write(B);
21.14
Concurrent Execution
and
Schedule
Concurrent Execution
Concurrent Execution
Serial Schedule
T1 T2
Read(A);
Temp=0.2*A;
A:=A-Temp;
Write(A);
Schedule2 (T2 followed by T1) Read(B);
B:=B+Temp;
Write(B);
Read(A);
A:=A-100;
Write(A);
Read(B);
B:=B+100;
Write(B);
Concurrent Schedule
Concurrent Schedule
In a concurrent schedule, operations from different concurrent transactions are
interleaved.
The number of possible schedules for a set of n transactions is much larger than n!
Schedule1
T1 T2 Schedule3
Read(A);
A:=A-100;
Write(A);
Read(A);
Temp=0.2*A;
A:=A-Temp;
Write(A);
Read(B);
B:=B+100;
Write(B);
Read(B);
B:=B+Temp;
Write(B);
Concurrent Schedule...
Schedule3
Schedule4 Schedule5
T1 T2 T1 T2 T1 T2
Read(A); Read(A); Read(A);
A:=A-100; A:=A-100; A:=A-100;
Read(A);
Write(A); Write(A);
Read(A); Temp=0.2*A;
Read(A);
Temp=0.2*A; A:=A-Temp;
Temp=0.2*A;
A:=A-Temp; Write(A);
A:=A-Temp;
Write(A); Read(B); Read(B);
Serializability
A concurrent schedule is serializable if it is equivalent to a
serial schedule
T1 T2 T1 T2 T1 T2
Read(A); Read(A); Read(A);
Write(A); Read(A); Write(A);
Read(A); Write(A); Read(A);
Write(A); Read(B); Read(B);
Read(B); Write(A); Write(A);
Write(B); Read(B); Read(B);
Read(B); Write(B);
Write(B)
Write(B); Write(B); Write(B);
Schedule3 Schedule4 Schedule5
Serializability
Schedule 3 Schedule 6
Conflict Serializability (Cont.)–Example of Conflict Serializable
R(Y)
R(X)
R(Y) As No cycle is formed in the Among 6 possible serial
R(Z) Precedence graph, So we can schedule which one is actually
W(Y) Say that the schedule is T3 holding?
Conflict Serializable. To find out that we have to do
W(Z) Topological Sorting
R(Z) s1 T1 T2 T3
W(X)
W(Z) T1 T2 s2 T1 T3 T2
s3 T2 T1 T3
s4 T2 T3 T1
T2 T3 T1
s5 T3 T1 T2
T3
s6 T3 T2 T1
View Serializability
▰ Let S and S´ be two schedules with the same set of transactions. S and S´ are view
equivalent if the following three conditions are met, for each data item Q,
▰ As can be seen, view equivalence is also based purely on reads and writes alone.
View Serializability (Cont.) S1 : Serial schedule <T1,T2>
37
Check S with S1
Initial Read(Q) in S (by T1) is maintained by T1 of S1.
Final Write(Q) in S (by T3) is maintained by T3 of S1.
After writing no Read() is there ; so 2nd condition is not
Applicable.
S
T1 T2
T3
When a Blind write is present in view serializable schedule then that Schedule cannot be in
conflict serializable .
Test for View Serializability
Recoverable
Cascadeless
44
Cascadeless Schedules
T1 T2 T3
R(A)
W(A)
Dirty Read R(A)
W(A)
Dirty Read
R(A)
FAIL
Commit
commit
T1 T2 T3
commit
R(A)
Order of dependency is T1→T2→T3 W(A)
So, commit should be T1 →then T2 →then T3 Commit
If a failure occurs here then T1 will If there is no dirty read then R(A)
cascadeless schedule is obtained. W(A)
Rollback and T2 , T3 will also Commit
Rollback. So such type of schedule
is known as Cascading Rollback Degree of concurrency is R(A)
decreased Commit
Schedule
THANK YOU...
46
Cascadeless Schedules
T1 T2 T3
R(A)
W(A)
Dirty Read R(A)
W(A)
Dirty Read
R(A)
FAIL
Commit
commit
T1 T2 T3
commit
R(A)
Order of dependency is T1→T2→T3 W(A)
So, commit should be T1 →then T2 →then T3 Commit
If a failure occurs here then T1 will If there is no dirty read then R(A)
cascadeless schedule is obtained. W(A)
Rollback and T2 , T3 will also Commit
Rollback. So such type of schedule
is known as Cascading Rollback Degree of concurrency is R(A)
decreased Commit
Schedule