Outline: Concurrency Control
Outline: Concurrency Control
Concurrency Control
Part 2
R&G - Chapter 17
Last time:
Locking Granularity
Multiple-Granularity Locks
Shouldnt have to make same decision for all
transactions!
Data containers are nested:
Database
contains
Tables
Pages
Tuples
Tables
Pages
Tuples
Database
Database
Tables
Each Xact starts from the root of the hierarchy.
Pages
To get S or IS lock on a node, must hold IS or IX on
parent node.
Tuples
What if Xact holds S on parent? SIX on parent?
SIX
S
X
- -
- - -
- - - - - - -
IS
IX
SIX
Database
Tables
Pages
Tuples
Outline
Today: advanced locking issues
Locking granularity
Tree locking protocols
Phantoms & predicate locking
Tables
Tuples
T3 reads all of R:
T3 gets an S lock on R.
OR, T3 could behave like T2; can
use lock escalation to decide which.
Lock escalation dynamically asks for
coarser-grained locks when too many
low level locks acquired
IS IX
SIX
IS
IX
SIX
Locking in B+ Trees
What about locking indexes --- why is it needed?
Tree-based indexes present a potential concurrency
bottleneck:
If you ignore the tree structure & just lock pages while
traversing the tree, following 2PL.
Root node (and many higher level nodes) become bottlenecks
because every tree access begins at the root.
ROOT
Example
35
23
20*
38
G
22*
23*
24*
I
35*
36*
ROOT
Example
20*
22*
23*
24*
38
I
35*
41*
Do:
1) Delete 38*
2) Insert 25*
36*
44
41*
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, usually better than previous alg.
Outline
Today: advanced locking issues
Locking granularity
Tree locking protocols
Phantoms & predicate locking
D
38*
44*
F
H
D
38*
35
44
20
23
Do:
1) Search 38*
2) Delete 38*
3) Insert 45*
4) Insert 25*
20
E
44*
The Problem
Predicate Locking
Index Locking
Data
Index
r=1
AND
2. The lock for the file itself
To prevent records with rating = 1 from being added or
deleted
Summary
Multiple granularity locking flexibility for each
xact to choose locking granularity independently
Tree-structured indexes:
Straightforward use of 2PL very inefficient.
Instead, design specialized locking protocols for trees
Other work in this (important) area, e.g., Lehman-Yao