Xiangyao Yu 10/5/2020
CS 764: Topics in Database Management Systems Lecture 9: B-tree Locking
1
CS 764: Topics in Database Management Systems Lecture 9: B-tree - - PowerPoint PPT Presentation
CS 764: Topics in Database Management Systems Lecture 9: B-tree Locking Xiangyao Yu 10/5/2020 1 Todays Paper: B-tree Locking ACM Trans. Database Syst. 1981 2 Agenda Index in OLTP database B tree, B+ tree, and B* tree B link -tree 3
1
2
3
4
Primary index (id)
Data store
Select name From student Where id=xxx ptr to tuple or page id
5
Primary index (id)
Data store
Select name From student Where id=xxx Primary index (id)
Data store
Select name From student Where email=xxx Secondary index (email) ptr to tuple or page id id ptr to tuple or page id
6
Algorithm Average Worst case Space O(n) O(n) Search O(log n) O(log n) Insert O(log n) O(log n) Delete O(log n) O(log n)
7
Algorithm Average Worst case Space O(n) O(n) Search O(log n) O(log n) Insert O(log n) O(log n) Delete O(log n) O(log n)
8
10 8 14 16 4 9 13 15 17 19
B-tree
9
10 8 14 16 4 9 13 15 17 19 10 8 14 16 4 9 13 15 17 19
B-tree B+ tree
10
10 8 14 16 4 9 13 15 17 19 10 8 14 16 4 9 13 15 17 19
B-tree B+ tree
10 8 14 16 4 9 13 15 17 19
B* tree
9 19 19
high key
11
12
13
14
10 8 14 16 4 9 13 15 17 19 10 8 14 16 4 9 13 15 17 19
Blink tree B* tree
9 19 19
link pointer
9 19 19
15
5 10 23 11 13 17 19
… … … …
Key: 13
…
root
… …
16
5 10 23 11 13 17 19
… … … …
Key: 13
…
root
… …
17
18
5 10 23
… …
root
… …
11 13 17 23
… … … …
F
19
5 10 23
… …
root
… … stack = { F root, }
11 13 17 23
… … … …
F
20
5 10 23
… …
root
… …
11 13 17 23
… … … …
F
initially, w is the data page to be inserted
21
5 10 23
… …
root
… …
11 13 17 23
… … … …
F
22
5 10 23 11 13 17 23
… … … … …
root
… …
A
…
B
Allocate new block on disk
F
23
5 10 23 11 13 17 23
… … … … …
root
… …
11 13 14 17 23
…
create two pages in memory
A B F
24
5 10 23 11 13 17 23
… … … … …
root
… …
11 13 14 17 23
…
A B F
update the two disk pages (page B first)
25
5 10 23 11 13 14
… …
root
… …
A
17 23
B
F
update the two disk pages (page B first)
26
5 10 23 11 13 14
… …
root
… …
F A
17 23
B
try to insert (key=14, ptr=B) to F
27
5 10 14 23 11 13 14
… …
root
… …
F A
17 23
B
insert (key=14, ptr=B) to F
28
5 7 9 10 12 13 14
… …
root
… …
F A
17 23
B
At most three locks are being during an insert
11 14 23
29
root
… …
At most three locks are being during an insert
5 7 9 10 12 13 14
… …
F A
17 23
B
11 14 23
30
root
… …
At most three locks are being during an insert
5 7 9 10 12 13 14
… …
F A
17 23
B
11 14 23
31
32
33
34