Professional Documents
Culture Documents
Lecture #24-25
Concurrency Controls
CONCURRENT EXECUTIONS
Benefits of Concurrency
Benefits of Concurrency
Problems of Concurrency
▪ Concurrent access is relatively easy if all users are only
reading data, as there is no way that they can interfere
with one another.
▪ However, when two or more users are accessing the
database simultaneously and
o at least one is updating data,
o there may be interference that can result in
inconsistencies.
▪ However, although two transactions may be perfectly
correct in themselves,
o the uncontrolled interleaving of operations in this way
may produce an incorrect result,
o thus compromising the integrity and consistency of the
database. 8
Problems of Concurrency
Time T1 T2 BALx
t1 100
Begin Transaction
t2 read(balx) 100
Begin Transaction
t3 read(balx) 100
balx = balx + 100 100
t4
(balx 200)
balx = balx – 10 100
t5
(balx 90)
t6 write(balx) 200
t7 commit 200
t8 write(balx) 90
Fig 1 t9 commit 90
13
Time T3 T4 BALx
t1 100
Begin Transaction
t2 read(balx) 100
t3 balx = balx + 100 100
t4 write(balx) 200
Begin Transaction
⋮
t5 read(balx) 200
t6 rollback 100
t7 balx = balx - 10 100
t8 write(balx) 190
Fig 2 t9 commit 190
16
17
21
LOCKING
22
LOCKING
▪ These rules can conveniently be summarized by means
of a lock type compatibility matrix (Fig. 4).
▪ Matrix is interpreted as follows: Consider some tuple t.
Transaction A
X S –
Transaction B
X N N Y
S N Y Y Fig 4
– Y Y Y
▪ Suppose transaction A currently holds a lock on t as
indicated by the entries in the column headings (dash =
no lock);
o and suppose some distinct transaction B issues a
request for a lock on t as indicated by the entries down
the left-hand side. 24
Transaction B
X N N Y
S N Y Y
– Y Y Y
26
29
31