You are on page 1of 17

Database

Management
System

Lecture - 44
© Virtual University of Pakistan
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 ……..
© Virtual University of Pakistan ?
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

© Virtual University of Pakistan


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) ……..


© Virtual University of Pakistan
Serial Execution
An execution where transaction are
executed in a serial
Schedule or History
For two transactions two serial
executions or schedules are possible
© Virtual University of Pakistan
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

© Virtual University of Pakistan


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
© Virtual University of Pakistan
Lesson?
Serial schedule is guaranteed
correct, should we adopt it?
NNNNNNo, that will be
inefficient, under utilization of the
resources
Disliked by users
© Virtual University of Pakistan
Interleaved Schedule
We would prefer concurrent
execution, multiple users accessing
database at the same time
An interleaved schedule consists of
operations from different transactions
© Virtual University of Pakistan
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}
© Virtual University of Pakistan
Interleaved Schedule
Interleaved schedule provides
concurrent execution BUT
Three problems of concurrent
access may be encountered
© Virtual University of Pakistan
Real Problem
Two transactions
 Writing different variables
 Reading same variable
 Accessing same variable and one of
them writing
Conflicting operations
Conflicting transactions
© Virtual University of Pakistan
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
© Virtual University of Pakistan
Serializability

Two major approaches


 Locking
 Timestamping

© Virtual University of Pakistan


Locking
An object is locked before it
performs any operation
Two types of operations, two
types of locks
Shared and esclusive
© Virtual University of Pakistan
Lock Compatibility
TA holds TB requests
Shared Exclusive

YES NO
Shared

Exclusive NO NO

© Virtual University of Pakistan


Database
Management
System

Lecture - 44
© Virtual University of Pakistan

You might also like