Unit 4 CH1 Transactions
Unit 4 CH1 Transactions
Transactions
Introduction:
Sequence of actions that form a single logical unit of work are called transactions.
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
ACID Properties
To ensure integrity of the data, we require the database
system maintain the following properties of the
transactions:
Atomicity.
Consistency
Isolation
Durability
Atomicity: Either all operations of the transaction are reflected properly in the
database, or none are.
Example: Transferring money between accounts either completes fully or
doesn't happen at all.
• Active, the initial state; the transaction stays in this state while it is
starting execution.
• Failed, after the discovery that normal execution can no longer proceed.
a concurrent schedule
Concurrent Executions:
We consider only two operations: read and write.
1. Conflict serializability
2. View serializability
Conflict Serializability:
If Ii and Ij refer to different data items, then we can swap Ii and Ij without
affecting the results of any instruction in the schedule.
If Ii and Ij refer to same data item Q, then the order of two steps may matter.
R(A) W(A)
W(A) R(A) Conflict Pair
W(A) W(A)
R(A) W(B)
R(B) W(A)
W(B) R(A) Non Conflict Pair
W(A) R(B)
W(B) W(A)
R(B) R(A)
Conflict Serializability:
Hint: Check adjacent Non Conflict Pair and then swap the positions
Conflict Serializability: Example1
Is this schedule a
conflict serializable schedule?
Conflict Serializability: Example1
Swap
Swap
Swap
Swap
T1 T2
R(A)
W(A)
R(A)
W(A)
R(B)
T1 T2 T1 T2
R(A) R(A)
W(A) W(A)
R(A) R(B)
R(B) R(A)
W(A) W(A)
Is this schedule a
conflict serializable schedule?
NO!!
Conflict Serializability: Example1
Is this schedule a
conflict serializable schedule?
NO!!
Conflict Serializability: Example4
Is this schedule a
conflict serializable schedule?
NO!!
View Serializability:
commit
Is this schedule a
view serializable schedule?
YES!!
Precedence Graph(Testing of Serializability)
• Precedence Graph or Serialization Graph is used
commonly to test Conflict Serializability of a schedule.
• Assume a schedule S. For S, we construct a graph
known as precedence graph.
• This graph has a pair G = (V, E), where V consists a
set of vertices, and E consists a set of edges. The
set of vertices is used to contain all the transactions
participating in the schedule.
• The set of edges is used to contain all edges Ti ->Tj
for which one of the three conditions holds:
1. Create a node Ti → Tj if Ti executes write (Q) before
Tj executes read (Q).
2. Create a node Ti → Tj if Ti executes read (Q) before
Tj executes write (Q).
3. Create a node Ti → Tj if Ti executes write (Q) before
• 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.
• If a precedence graph for schedule S contains a
cycle, then S is non-serializable.
• If the precedence graph has no cycle, then S is
known as serializable.
Precedence Graph: Examples
Precedence Graph: Examples
Example: To check whether a schedule is conflict
serializable or NOT ?
T1 T2 T3 Precedence Graph
R(X)
R(y) T2
R(X)
R(Y)
T1 T3
R(Z)
- Check the conflict pair in other transaction and
W(Y) draw edge
W(Z) - Check if there is a loop/cycle in graph ?
R(Z) NO!!!.
W(X) Means this is a conflict serializable
W(Z) Then it can be serializable
It is consistent too.