Transaction Management Overview: Chapter 16, 3/e
Transaction Management Overview: Chapter 16, 3/e
Chapter 17, 3e
A
T1 T2 Dependency graph
B
• The cycle in the graph reveals the problem.
The output of T1 depends on T2, and vice-
versa.
Introduction to Database Management Systems, Raghu Rama Krishnan 17
Dependency Graph
T1 T2 T1 T2
T4 T3 T3 T3
Introduction to Database Management Systems, Raghu Rama Krishnan 28
Multiple-Granularity Locks
• Hard to decide what granularity to lock
(tuples vs. pages vs. tables).
• Shouldn’t have to decide!
• Data “containers” are nested:
Database
Tables
contains
Pages
Tuples
Introduction to Database Management Systems, Raghu Rama Krishnan 29
Solution: New Lock Modes, Protocol
• Allow Xacts to lock at each level, but with a
special protocol using new “intention” locks:
Before locking an item, Xact -- IS IX S X
must set “intention locks”
on all its ancestors. --
23 F 38 44 C
G H I D E
20* 22* 23* 24* 35* 36* 38* 41* 44*
Introduction to Database Management Systems, Raghu Rama Krishnan 40
A Better Tree Locking Algorithm
(See Bayer-Schkolnick paper)
• Search: As before.
• Insert/Delete:
Set locks as if for search, get to leaf, and set
X lock on leaf.
If leaf is not safe, release all locks, and restart
Xact using previous Insert/Delete protocol.
• Gambles that only leaf node will be modified;
if not, S locks set on the first pass to leaf are
wasteful. In practice, better than previous alg.
Introduction to Database Management Systems, Raghu Rama Krishnan 41
ROOT Do:
20 A 1) Delete 38*
Example 2) Insert 25*
4) Insert 45*
5) Insert 45*,
then 46*
35 B
23 F 38 44 C
G H I D E
20* 22* 23* 24* 35* 36* 38* 41* 44*
Introduction to Database Management Systems, Raghu Rama Krishnan 42
Even Better Algorithm
• Search: As before.
• Insert/Delete:
Use original Insert/Delete protocol, but set
IX locks instead of X locks at all nodes.
Once leaf is locked, convert all IX locks to X
locks top-down: i.e., starting from node
nearest to root. (Top-down reduces chances
of deadlock.)
(Contrast use of IX locks here with their use in
multiple-granularity locking.)
Introduction to Database Management Systems, Raghu Rama Krishnan 43
Hybrid Algorithm
Set X locks
modified ROOT
objects new
Introduction to Database Management Systems, Raghu Rama Krishnan 46
Validation
Ti
Tj
R V W
R V W
Ti
R V W
Tj
R V W
MAIN VERSION
SEGMENT O’ POOL
(Current O (Older versions that
versions of may be useful for
DB objects) O’’ some active readers.)
Reader Xact
• For each object to be read: T
Finds newest version with WTS < TS(T).
(Starts with current version in the main
segment and chains backward through
earlier versions.)
• Assuming that some version of every object
exists from the beginning of time, Reader
Xacts are never restarted.
However, might block until writer of the
appropriate version commits.
V
Introduction to Database Management Systems, Raghu Rama Krishnan RTS(V) T 63
Transaction Support in SQL-92
• Each transaction has an access mode, a
diagnostics size, and an isolation level.