Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS522 Advanced database Systems

Similar presentations


Presentation on theme: "CS522 Advanced database Systems"— Presentation transcript:

1 CS522 Advanced database Systems
7/2/2018 CS522 Advanced database Systems 6. B+ tree Huiping Guo Department of Computer Science California State University, Los Angeles

2 Outline Introduction to B+ tree indexing B+ tree inserts
7/2/2018 Outline Introduction to B+ tree indexing B+ tree inserts B+ tree deletes 6. B+ Tree CS522_S16

3 B+ Tree: Most Widely Used Index
7/2/2018 B+ Tree: Most Widely Used Index Adjust gracefully to inserts and deletes Tree structure grows and shrinks dynamically The leaf pages are linked. Why? Index Entries Data Entries ("Sequence set") (Direct search) 6. B+ Tree CS522_S16 9

4 Characteristics of a B+ tree
Operations (insert, delete) on the tree keep it balanced A minimum occupancy of 50% is guaranteed for each node except the root Searching for a record requires just a traversal from the root to the appropriate leaf—the height of the tree 6. B+ Tree CS522_S16

5 B+ Tree parameters Order d Occupancy – at least half full Balance
A parameter of a tree A measure of the capacity of a tree Occupancy – at least half full Each node contain m entries d<=m<=2d Exception: root node 1<=m<=2d Balance Keep the height of a tree from growing fast Fan-out The average number of children a node has 6. B+ Tree CS522_S16

6 B+ Trees in Practice Typical order: 100 Average fan-out = 133
7/2/2018 B+ Trees in Practice Typical order: 100 Average fan-out = 133 Typical capacities: Height 4: 1334 = 312,900,700 pages Height 3: 1333 = 2,352,637 pages Can often hold top levels in buffer pool: Level 1 = page = Kbytes Level 2 = pages = Mbyte Level 3 = 17,689 pages = 133 MBytes 6. B+ Tree CS522_S16

7 Example B+ Tree (no duplicates)
7/2/2018 Example B+ Tree (no duplicates) Search begins at root, and key comparisons direct it to a leaf (as in ISAM). Search for 5*, 15*, all data entries >= 24* ... Root d=2 2<=m<=4 13 17 24 30 2* 3* 5* 7* 14* 16* 19* 20* 22* 24* 27* 29* 33* 34* 38* 39* 6. B+ Tree CS522_S16 10

8 B+ Tree Insert (no duplicates)
Find the appropriate leaf Insert into the leaf there’s room  we’re done no room split leaf node into two Redistribute data entries evenly, copy up the middle key Insert an index entry to its parent node Recursively apply previous step if necessary To split index node, redistribute entries evenly, but push up the middle key 6. B+ Tree CS522_S16

9 B+ Tree Insert Examples
(a) no split space available in leaf (b) leaf page split (c) non-leaf page split (c) new root 6. B+ Tree CS522_S16

10 (a) Insert key = 32 (no split)
1<=m<=3 100 30 4 5 11 30 31 32 6. B+ Tree CS522_S16

11 (b) Insert key = 7 (leaf page split)
100 30 7 3 5 11 30 31 3 5 7 6. B+ Tree CS522_S16

12 (c) Insert key = 160 (non leaf page split)
100 160 120 150 180 180 150 156 179 180 200 160 179 6. B+ Tree CS522_S16

13 (d) New root, insert 45 30 new root 10 20 30 40 1 2 3 10 12 20 25 30
32 40 40 45 6. B+ Tree CS522_S16

14 Keys to B+ tree insertion
Observe how minimum occupancy is guaranteed in both leaf and index page splits. Note difference between copy-up and push-up Leaf page split Non-leaf page split Always copy(push) up the first key on the right affected page when there is a split. 6. B+ Tree CS522_S16

15 Exercise d=2 Insert a data entry with key 3. 6. B+ Tree CS522_S16
8 10 18 27 32 39 41 45 52 58 73 80 91 99 73 85 50 Insert a data entry with key 3. 6. B+ Tree CS522_S16

16 B+ Tree Delete Find the appropriate leaf Delete from the leaf
still at least half full  we’re done below half full borrow a <key,pointer> from one sibling node or merge with a sibling node, and delete from a parent node Recursively apply previous step if necessary When do we need a new ROOT (or decrease the height of the tree)?? 6. B+ Tree CS522_S16

17 B+ Tree Delete examples
a. The leaf page is still half full b. The leaf page is below half full, borrow an entry from a sibling node – leaf page redistribution c. The leaf page is below half full, merge with a sibling node d. Non-leaf page redistribution 6. B+ Tree CS522_S16

18 B+ Tree Delete Example d=2
Root 17 5 13 24 30 2* 3* 5* 7* 8* 14* 16* 19* 20* 22* 24* 27* 29* 33* 34* 38* 39* Delete 19* Delete 20* 6. B+ Tree CS522_S16

19 Delete 20*: Re-distribution (leaf)
Root 17 5 13 24 27 30 2* 3* 5* 7* 8* 14* 16* 20* 22* 24* 27* 29* 33* 34* 38* 39* 6. B+ Tree CS522_S16

20 Then delete 24*, Merge (leaf)
Root 17 5 13 27 30 2* 3* 5* 7* 8* 14* 16* 22* 24* 27* 29* 33* 34* 38* 39* 6. B+ Tree CS522_S16

21 Delete 24* Pull down root 17 Root 6. B+ Tree CS522_S16 2* 3* 7* 14*
16* 22* 27* 29* 33* 34* 38* 39* 5* 8* Root 30 13 5 17 6. B+ Tree CS522_S16

22 Another example of deletion
7/2/2018 Another example of deletion d=2 Delete 24* Non leaf page re-distribution Root 22 5 13 17 20 25 30 3* 2* 5* 7* 8* 14* 16* 17* 18* 20* 21* 22* 24* 27* 29* 33* 34* 38* 39* 6. B+ Tree CS522_S16 17

23 After deleting 24* & leaf page merge
Root 13 5 17 20 22 30 14* 16* 17* 18* 20* 33* 34* 38* 39* 22* 27* 29* 21* 7* 5* 8* 3* 2* 6. B+ Tree CS522_S16

24 Non-leaf page redistribution
Alternative 1: move over 1 entry(20) Root 20 5 13 17 22 30 2* 3* 5* 7* 8* 14* 16* 17* 18* 20* 21* 22* 27* 29* 33* 34* 38* 39* 6. B+ Tree CS522_S16

25 Non-leaf page redistribution
Alternative 2: move over 2 entry (17,20) Root 17 5 13 20 22 30 2* 3* 5* 7* 8* 14* 16* 17* 18* 20* 21* 22* 27* 29* 33* 34* 38* 39* 6. B+ Tree CS522_S16

26 Exercise d=2 8 10 18 27 32 39 41 45 52 58 73 80 91 99 73 85 50 Delete a data entry with key 8. Only left sibling is checked Delete a data entry with key 8. Only right sibling is checked Delete a data entry with key 91 in the original tree Successively delete 32, 39, 41, 45, 73 from the original tree 6. B+ Tree CS522_S16


Download ppt "CS522 Advanced database Systems"

Similar presentations


Ads by Google