1 / 20

B+ Tree

Index tuning--. B+ Tree. overview. B + -Tree Scalability. Typical order: 100. Typical fill-factor: 67%. average fanout = 133 Typical capacities (root at Level 1, and has 133 entries): Level 5: 133 4 = 312,900,700 records Level 4: 133 3 = 2,352,637 records

lang
Download Presentation

B+ Tree

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Index tuning-- B+ Tree

  2. overview

  3. B+-Tree Scalability Typical order: 100. Typical fill-factor: 67%. average fanout = 133 Typical capacities (root at Level 1, and has 133 entries): Level 5: 1334 = 312,900,700 records Level 4: 1333 = 2,352,637 records Can often hold top levels in buffer pool: Level 1 = 1 page = 8 Kbytes Level 2 = 133 pages = 1 Mbyte Level 3 = 17,689 pages = 133 MBytes

  4. A Note on `Order’ Order (d) concept replaced by physical space criterion in practice (`at least half-full’). Index pages can typically hold many more entries than leaf pages. Variable sized records and search keys mean different nodes will contain different numbers of entries. Even with fixed length fields, multiple records with the same search key value (duplicates) can lead to variable-sized data entries

  5. Inserting a Data Entry into a B+ Tree Find correct leaf L. Put data entry onto L. If L has enough space, done! Else, must splitL (into L and a new node L2) Redistribute entries evenly, copy upmiddle key. Insert index entry pointing to L2 into parent of L. This can happen recursively To split index node, redistribute entries evenly, but push upmiddle key. (Contrast with leaf splits.) Splits “grow” tree; root split increases height. Tree growth: gets wider or one level taller at top.

  6. Inserting 7 & 8 into Example B+ Tree Observe how minimum occupancy is guaranteed in both leaf and index pg splits. Root 30 13 17 24 39 3 5 19 20 22 24 27 38 2 7 14 16 29 33 34 (Note that 5 is copied up and continues to appear in the leaf.) 30 5 13 17 24 3 5 2 7 8

  7. Insertion (Cont) Note difference between copy-upand push-up; be sure you understand the reasons for this. (Note that 17 is pushed up and only appears once in the index. Contrast this with a leaf split.) 17 5 13 24 30 30 5 13 17 24 3 5 2 7 8

  8. Example B+ Tree After Inserting 8 Root 17 24 5 13 30 39 2 3 5 7 8 19 20 22 24 27 38 29 33 34 14 16 • Notice that root was split, leading to increase in height. • In this example, we can avoid splitting by re-distributing entries; however, this is usually not done in practice. Why? • checking whether redistribution is possible may increase I/Os

  9. Deleting a Data Entry from a B+ Tree Start at root, find leaf L where entry belongs. Remove the entry. If L is at least half-full, done! If L has only d-1 entries, Try to re-distribute, borrowing from sibling (adjacent node with same parent as L). If re-distribution fails, mergeL and sibling. If merge occurred, must delete entry (pointing to L or sibling) from parent of L. Merge could propagate to root, decreasing height.

  10. Example Tree After (Inserting 8, Then) Deleting 19 Deleting 19 is easy. Root 17 24 5 13 30 39 2 3 5 7 8 24 27 38 29 33 34 14 16 20 22

  11. Example Tree After Deleting 20 ... Deleting 20 is done with re-distribution. Notice how middle key is copied up. Root 17 27 5 13 30 39 2 3 5 7 8 22 24 27 29 38 33 34 14 16

  12. ... And Then Deleting 24 Must merge. Observe `toss’ of index entry (on right), and `pull down’ of index entry (below). 30 39 22 27 38 29 33 34 Root 5 13 17 30 3 39 2 5 7 8 22 38 27 33 34 14 16 29

  13. Example of Non-leaf Re-distribution (Delete 24) In contrast to previous example, can re-distribute entry from left child of root to right child. 2 3 5 7 8 39 17 18 38 20 21 22 27 29 33 34 14 16 22 Root 27 30 17 20 5 13 39 38 22 24 27 29 33 34 2 3 5 7 8 17 18 20 21 14 16 22 Root 30 17 20 5 13

  14. After Re-distribution Intuitively, entries are re-distributed by `pushingthrough’ the splitting entry in the parent node. It suffices to re-distribute index entry with key 20; we’ve re-distributed 17 as well for illustration. Root 17 22 30 5 13 20 2 3 5 7 8 39 17 18 38 20 21 22 27 29 33 34 14 16

  15. B+tree deletions in practice • Often, mergeing/coalescing is not implemented • Too hard and not worth it!

  16. Duplicates • Using overflow page • Several leaf pages may contain entries with the same key • To retrieve all data entries with a given key, we search for theleft-most data entry with the key, then follow the leaf sequence pointers to find other pages.

  17. B+-Tree Performance Tree levels Tree Fanout Size of key Page utilization Tree maintenance Online On inserts On deletes Offline Tree locking Tree root in main memory

  18. B+-Tree Performance Key length influences fanout Choose small key when creating an index Key compression Prefix compression (Oracle 8, MySQL): only store that part of the key that is needed to distinguish it from its neighbors: Smi, Smo, Smy for Smith, Smoot, Smythe. Front compression (Oracle 5): adjacent keys have their front portion factored out: Smi, (2)o, (2)y. There are problems with this approach: Processor overhead for maintenance Locking Smoot requires locking Smith too.

  19. Prefix Key Compression • Key values in index entries only `direct traffic’; can often compress them. • E.g., If we have adjacent index entries with search key values Dannon Yogurt, David Smith and Devarakonda Murthy, we can abbreviate David Smith to Dav. (The other keys can be compressed too ...) • Is this correct? Not quite! What if there is a data entry Davey Jones? (Can only compress David Smith to Davi) • In general, while compressing, must leave each index entry greater than every key value (in any subtree) to its left. • Insert/delete must be suitably modified.

  20. summarize

More Related