Chapter 3 Transaction concepts
Chapter 3 Transaction concepts
Transaction Concepts
By Prof. Ashwini Satkar
Agenda
Transaction Concepts
Transaction Properties
Transaction States
Concurrent execution
Serializability
Transaction
A sequence of operations that must be treated as an
undivided unit.
A transaction is a sequence of one or more SQL
statements that are executed as a single unit of work.
Operations read and write
read(x)-Access resource x without modifying it.
write(x)-Modify resource x.
Transaction must be either committed or aborted
Example
A transfer between account. Money should be transferred or
withdrawn from account.
ACID Properties
Atomicity:
We mean that either the entire transaction takes place at once
or doesn’t happen at all. There is no midway i.e. transactions
do not occur partially.
Each transaction is considered as one unit and either runs to
completion or is not executed at all.
It involves the following two operations.
Abort: If a transaction aborts, changes made to the database are
not visible.
Commit: If a transaction commits, changes made are visible.
Atomicity is also known as the ‘All or nothing rule’.
Consider the following transaction T consisting of T1 and T2:
Transfer of 100 from account X to account Y.
Suppose T has been executed till Read (Y) and then T’’ starts.
As a result, interleaving of operations takes place due to which T’’ reads the
correct value of X but the incorrect value of Y and sum computed by
T’’: (X+Y = 50, 000+500=50, 500)
is thus not consistent with the sum at end of the transaction:
T: (X+Y = 50, 000 + 450 = 50, 450).
This results in database inconsistency, due to a loss of 50 units. Hence,
transactions must take place in isolation and changes should be visible only after
they have been made to the main memory.
Durability
In non-serial schedules,
Multiple transactions execute concurrently.
Operations of all the transactions are inter leaved or mixed with
each other.
Characteristics-
Non-serial schedules are NOT always-
Consistent
Recoverable
Cascadeless
Strict
Non-Serial Schedule Examples
Concurrent transaction
Concurrent transaction or execution includes multiple transactions
which are executed concurrently or simultaneously in the system.
We take ATM machines and we do not use concurrency, then multiple
persons cannot draw money at a time in different places. This is where
we need concurrency.
Advantages
The advantages of the concurrent transactions are as follows :
Increases throughput which is nothing but number of transactions
completed per unit time.
It reduces the waiting time.
Disadvantage
The disadvantage is that the execution of concurrent transactions may
result in inconsistency.
Concurrent transaction
Transaction which is in consistent state.
T1 T2
Read(A)
A=A-50
Write(A)
Read(A)
Temp=A*0.1
A=A-temp
Write(A)
Read(B)
B=B+50
Write(B)
Read(B)
B=B+temp
Write(B)
Concurrent transaction
Transaction which is inconsistent state.
T1 T2
Read(A)
A=A-50
Read(A)
Temp=A*0.1
A=A-temp
Write(A)
Write(B)
Write(A)
Read(B)
B=B+50
Write(B)
B=B+temp
Write(B)
Concurrency Problems
When multiple transactions execute concurrently in an uncontrolled
or unrestricted manner, then it might lead to several problems.
These problems are commonly referred to as concurrency problems
in a database environment.
The five concurrency problems that can occur in the database are:
Temporary Update Problem
Incorrect Summary Problem
Lost Update Problem
Unrepeatable Read Problem
Phantom Read Problem
Temporary Update Problem
T1 T2
R(X)
W(X)
W(X)
commit
R(X)
Commit