Ch5 Transaction
Ch5 Transaction
Concepts
1. Introduction To
transaction Processing
1.1 Single User VS Multi User
Systems
One criteria to classify Database is
according to number of user that
concurrently connect to the system.
Single User: only one user use the system
in each time
Multi User: many users use the system in
the same time
1.2 Transactions, Read and Write
Operations, and DBMS Buffers
What is a Transaction?
Transaction is an executing program that forms a logical unit of
database processing.
A transaction is a unit of program execution that accesses and
Ti: read (A) (withdraw from A)
A := A – 5000
write (A); (update A)
read (B) (deposit B)
B := B + 5000
write (B) (update B)
Example of Fund Transfer
Explicitly specified integrity constraints such as primary keys
and foreign keys
Implicit integrity constraints
– e.g. sum of balances of all accounts, minus sum of loan
amounts must equal value of cash-in-hand
Example of Fund Transfer
temporarily inconsistent.
When the transaction completes successfully the
6. write(B)
Isolation can be ensured trivially by running transactions serially that is, one after
the other.
ACID Properties
Atomicity.
Either all operations of the transaction are properly
Isolation.
Although multiple transactions may execute
System Failure
Media Failure
Reasons for a transaction fails in the
middle of execution
Begin
Abort
Transaction
Active
Abo
rt
Failed Aborted
(Terminate)
is executing
Partially committed
after the final statement has been executed.
Failed
after the discovery that normal execution can no longer
proceed.
State of transaction
Aborted
after the transaction has been rolled back and the
Operations
Read(A) – read value of data item A
Data Items
Objects in the data base
X
(Commit, T) complete operation of T
X = 100
Transaction A is reading record X = 100 and adding 15 to X, but this transaction is not yet
reflected on DB. As write operation is not performed. (Result temp_X = 115)
Transaction B also reads X but here it is not getting updated value after transaction A.
Hence, X = 100. Subtracting 25 from X. And write commit operation is performed on X.
Hence, X = 75
After performing transactions A and B, the value of X should have been X = 95.
But due to a lost update problem the result of Transaction B is lost and the final result is X
= 115.
Lost update problemA = 1000, B =2000
T1 T2
Read_item(A) A = 1000
A := A – 50 A = 950
Read_item(A)A = 1000
temp := 0.1*A
temp = 100
A:= A-temp
A=1000-
Write_item(A) A = 950 100
= 900
Read_item(B) B = 2000
A = 900
Write_item(A)
Read_item(B)
B = 2000
B := B + 50 B = 2050
Write_item(B) B = 2050
B = 2100
B := B + temp
Write_item(B)
B = 2100
Temporary Update
Problem:
T1 T2
- Write_item(R) R = 1000
Read_item(R) R = 1000 -
- RollBack
R = 3000
Inconsistency problem