Professional Documents
Culture Documents
Database Management Systems
Database Management Systems
Overview
B-trees:
Give up on sequentiality of index Try to get balance the structure
B means balanced.
Can have as many levels of index as appropriate Make sure each block is between half used and completely full
3 5 11
B+ tree Example
Fanout: n=3
ICS214A
30 35 30 100 101 110 100 120 130 150 156 179 180 200
3 Notes 06
Root
57
81
to keys
< 57
to keys
57<= k<81
to keys
81<=k<95
95
to keys
>=95
ICS214A
Notes 06
ICS214A
Notes 06
95
57
81
In textbooks notation
NonLeaf
30 30
n=3
Leaf
30 35 30 35
ICS214A
Notes 06
ICS214A
Notes 06
Example
Full node min. node
30 30 35
n=3
120 150 180 3 5 11
Notes 06
Non-leaf
Leaf
ICS214A
Number of pointers/keys
Max Max ptrs keys Root Non-leaf (non-root) Leaf (non-root) n+1 n Min ptrs 2 Min keys 1
n+1
n
n
n
(n+1)/2
(n+1)/2
(n+1)/2-1
(n+1)/2
ICS214A
Notes 06
Range queries:
empID > 400 empID <= 600 100 <= empID < 400
ICS214A
Notes 06
10
Insertions
Cases: (a) simple case: space available in leaf (b) leaf overflow (c) non-leaf overflow (d) new root
ICS214A
Notes 06
11
n=3
30
ICS214A
30 31 32
Notes 06
3 5 11
12
n=3
3 57 11
30 30 31
ICS214A
3 5
Notes 06
13
n=3
180
Notes 06
ICS214A
160 179
180 200
14
n=3
10 20 30
30 32 40
10 12
20 25
40
ICS214A
Notes 06
40 45
15
1 2 3
Deletion
Cases:
(a) Simple case - no example (b) Coalesce with neighbor (sibling) (c) Redistribute keys (d) Cases (b) or (c) at non-leaf
ICS214A
Notes 06
16
n=4
10 20 30 40
ICS214A
Notes 06
40 50
17
Delete 50
n=4
ICS214A
Notes 06
35 40 50
10 20 30 35
18
n=4
25 26 30
10 14
20 22
30 37
ICS214A
Notes 06
40 45
19
1 3
ICS214A
Notes 06
20
ICS214A
Notes 06
21
We want to have a large n to reduce the tree height If a node corresponds to a block, we choose a largest n to fill up the block space.
ICS214A
Notes 06
22
B+tree Optimizations
To improve performance, we want to reduce the height. Two strategies:
decrease the number of leaf pages
shorten the data stored in leaf pages using compression techniques
Deciding the policy for maintaining B+tree is part of physical database design.
ICS214A
Notes 06
23
ICS214A
Notes 06
24
Suffix Compression
Bertolucci Copelletti ... Gambogi Bert Cop . .Gam . . Cooperativa .. Copelletti. . . Cooperativa Copelletti. . .
Beret
Bertolucci
a) Full key values stored in all nodes of the B*- tree b) Suffix compression for key values in high- level nodes
E.g.: If Bert is enough at the root node to do the routing, we dont need to store Bertolucci
ICS214A Notes 06 25
to keys < K1
to record to record to record with K1 with K2 with K3 to keys to keys to keys K1<x<K2 K2<x<k3 >k3
A B-tree has record pointers in non-leaf nodes In practice, B+trees are preferred, and widely used
ICS214A Notes 06 26
10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 85 105 65 125 25 45
B-tree example
ICS214A Notes 06 27
145 165
n=2