Transaction 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Database

System
Uncommitted Update Problem
TIME TA TB BAL

t1 Read (BAL) ……. 1000

t2 BAL=BAL+100 …….. 1000

t3 Write (BAL) …….. 1100

t4 ……. Read (BAL) 1100

t5 ……. BAL=BAL*1.5 1100

t6 ……. Write (BAL) 2650

t7 ROLLBACK …….. ?
Inconsistent Analysis
➢One transaction operates many records,
meanwhile another modifies some of them
effecting result of first
➢Suppose Tr-A computes interest on all
accounts balances and other moves balance
from one account to another
TIME TA TB
t1 Read (BAL_A) (5000) …….
t2 INT = BAS_A * .05 ……..
t3 TOT = TOT + INT ……..
t4 ……. …….
t5 ……. Read (BAL_A)
t6 ……. BAL_A=BAL_A – 1000
t7 ……. Write (BAL_A)
t8 ……. Read (BAL_E) (5000)
t9 ……. BAL_E = BAL_E + 1000
t10 ……. Write (BAL_E)
t11 Read (BAL_E) (6000) ……..
t12 INT = BAS_E * .05 ……..
t13 TOT = TOT + INT ……..
Serial Execution
➢An execution where transaction are
executed in a serial
➢Schedule or History
➢For two transactions two serial
executions or schedules are possible
Serial Execution
TA, TB BAL TB, TA BAL
Read (BAL)A 50 Read (BAL)B 50
(BAL = BAL – 10)A 50 (BAL=BAL * 2)B 50
Write (BAL)A 40 Write (BAL)B 100
Read (BAL)B 40 Read (BAL)A 100
(BAL=BAL * 2)B 80 (BAL = BAL – 10)A 100
Write (BAL)B 80 Write (BAL)A 90
Serial Execution
➢Different serial schedules may result
in a different final DB state, BUT
➢Serial execution is guaranteed to
leave DB in a consistent state
➢None of the three concurrent access
problems
Lesson?
➢Serial schedule is guaranteed
correct, should we adopt it?
➢NNNNNNo, that will be
inefficient, under utilization of the
resources
➢Disliked by users
Interleaved Schedule
➢We would prefer concurrent
execution, multiple users accessing
database at the same time
➢An interleaved schedule consists of
operations from different transactions
Schedule
TA = {Read(X), Write(X), commit}
TB = {Read(Y), Read(X), Write(Y), commit}
S1 = {RA(X), WA(X), CA, RB(Y), RB(X), WB(Y), CB}
S2 = {RB(Y), RB(X), WB(Y), CB, RA(X), WA(X), CA}
S3 = {RB(Y), RB(X), RA(X), WB(Y), CB, WA(X), CA}
S4 = {RA(X), RB(Y), RB(X), WA(X), CA, WB(Y), CB}
Interleaved Schedule
➢Interleaved schedule provides
concurrent execution BUT
➢Three problems of concurrent
access may be encountered
Real Problem
➢Two transactions
▪ Writing different variables
▪ Reading same variable
▪ Accessing same variable and one of
them writing
➢Conflicting operations
➢Conflicting transactions
Serializability
➢An interleaved schedule is
serializable if the final state of
the schedule is equivalent to a
serial schedule OR
➢A schedule where conflicting
operations are in a serial order
Serializability

➢Two major approaches


▪Locking
▪Timestamping
Locking
➢An object is locked before it
performs any operation
➢Two types of operations, two
types of locks
➢Shared and esclusive
Lock Compatibility
TA holds TB requests
Shared Exclusive

YES NO
Shared

Exclusive NO NO

You might also like