Indexing and Hashing: (Emphasis On B+ Trees)
Indexing and Hashing: (Emphasis On B+ Trees)
(emphasis on B+ trees)
By Huy Nguyen
Cs157b
0900-1015 TR
Lee, Sin-Min
Storage
• We have been studying database languages
and queries and have yet to study how data is
stored.
41 55 75
22 30 35 45 49 60 67 87 91 100
12 22 30 35 41 45 49 55 60 67 75 87 91 100
15 24 32 37 43 46 51 57 62 72 77 88 94 110
20 27 34 38 44 48 53 58 64 74 80 90 97 112
28 39 54 59 65 83 99 114
29 66 85 120
Search in a B+ Tree
• Search: Start at root; use key comparisons
to go to leaf.
Inserting a Data Entry into a B+
Tree
1) Find correct leaf node
2) Add index entry to the node
3) If enough space, done!
4) Else, split the node
Redistribute entries evenly between the current
node and the new node
5) Insert <middle key, ptr to new node> to the
parent
6) Go to Step 3
After
After
Deleting a Data Entry from a B+
Tree
1) Find correct leaf node
2) Remove the entry from the node
3) If the node is at least half full, done!
4) Else, possibly borrow some entries from a
sibling
5) If not possible, merge the node with the sibling
6) Delete the separator between the node and the
sibling from the parent node
7) Go to Step 3
After
Binary Trees VS. BTrees
• Binary tree only have 2 children max.