B+ Trees
Example of applications
Student record system in a university:
Indexed view: access to individual records
Sequential view: batch processing when posting
grades
Example: insertion
Block size = 4
Key : Last name
Block 1 ADAMS
BIXBY
CARSON COLE
Insert BAIRD :
Block 1
ADAMS BAIRD
Block 2 CARSON ..
BIXBY
COLE
Example: deletion
Block 1 ADAMS
BAIRD
BIXBY
Block 2 BYNUM
CARSON ..
CARTER ..
Block 3
BOONE
DENVER ELLIS
Block 4 COLE
DAVIS
Block
BERNE
CAGE
DUTTON
EVANS
FOLK
GADDIS
1
2
3
4
5
6
Tree indexes
This simple scheme is nice if the index fits in
memory.
If index doesnt fit in memory:
Divide the index structure into blocks,
Organize these blocks similarly building a tree
structure.
Tree indexes:
B Trees
B+ Trees
Simple prefix B+ Trees
Separators
Block
1
Range of Keys
Separator
ADAMS-BERNE
BOLEN
BOLEN-CAGE
CAMP
CAMP-DUTTON
EMBRY
EMBRY-EVANS
FABER
FABER-FOLK
FOLKS
FOLKS-GADDIS
10
root
EMBRY
Index set
BOLEN
ADAMS-BERNE
CAMP
FABER
CAMP-DUTTON
BOLEN-CAGE
FOLKS
EMBRY-EVANS
FOLKS-GADDIS
FABER-FOLK
5
11
B Trees
B-tree is one of the most important data structures
in computer science.
What does B stand for? (Not binary!)
B-tree is a multiway search tree.
Several versions of B-trees have been proposed,
but only B+ Trees has been used with large files.
A B+tree is a B-tree in which data records are in
leaf nodes, and faster sequential access is possible.
12
13
Pn-1 Kn Pn
Requirements:
K1 < K 2 < < K n
For any search key value K in the subtree pointed by Pi,
If Pi = P0, we require K < K1
If Pi = Pn, Kn K
If Pi = P1, , Pn-1, Ki < K Ki+1
14
K 1 r1 K 2
K n rn R
10*
15*
20
33
20*
27*
51
33*
37*
40*
46*
51*
63
55*
63*
97*
16
Examples: search for 5*, 16*, all data entries >= 24* ...
The last one is a range search, we need to do the sequential scan, starting from
the first leaf containing a value >= 24.
Root
13
2*
3*
5*
7*
14* 15*
17
24
30
17
18
2*
3*
5*
7*
8*
13
17
24
30
15* 16*
14*
You overflow
13
2*
3*
5*
7*
17
24
30
8*
19
Inserting 8* (cont.)
Copy up the
middle value
(leaf split)
13
17
24
30
Entry to be inserted in parent node.
(Note that 5 is
s copied up and
continues to appear in the leaf.)
2*
3*
13
5*
17
24
30
7*
8*
You overflow!
20
13
17
24
30
17
13
24
21
2*
3*
24
13
5*
7* 8*
14* 15*
30
22
23
24
2*
3*
24
13
5*
7* 8*
14* 16*
30
w
rflo
e
d
22*
un
You
22* 24*
27* 29*
25
2*
3*
27
13
5*
7* 8*
14* 16*
22* 24*
30
27* 29*
26
g!
n
w
li
flo sib
r
de ith
n
u
u ew
o
Y erg
M
Deleting 24*
2*
3*
5*
7*
8*
13
14* 16*
30
22*
17
27*
29*
33*
34*
38*
39*
30
27
2* 3*
5* 7* 8*
13
14* 16*
17
30
20
17* 18*
20* 21*
29
After Re-distribution
Intuitively, entries are re-distributed by `pushing
through the splitting entry in the parent node.
It suffices to re-distribute index entry with key 20;
weve re-distributed 17 as well for illustration.
Root
17
2* 3*
5* 7* 8*
13
14* 16*
20
17* 18*
20* 21*
22
30
30