1 / 15

B+-Trees

B+-Trees. Storage Technology: Topic 5. B+ Tree: Features. Insert/delete at log F N cost; keep tree height-balanced . (F = fanout, N = # leaf pages)

mickr
Télécharger la présentation

B+-Trees

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. B+-Trees Storage Technology: Topic 5

  2. B+ Tree: Features • Insert/delete at log F N cost; keep tree height-balanced. (F = fanout, N = # leaf pages) • Minimum 50% occupancy (except for root). Each node contains d <= m <= 2d entries. The parameter d is called the orderof the tree. • Supports equality and range-searches efficiently.

  3. Search • Search begins at root, and key comparisons direct it to a leaf (as in ISAM). • Search for 5*, 15*, all data entries >= 24* ... • Based on the search for 15*, we know it is not in the tree!

  4. Insertion • Start at root, find leaf L where entry belongs. • Put the data entry on the leaf L. • If the L has enough space for the entry, done! • Else, must split the leaf L into L and (new page) L2. • Redistribute entries evenly, copy upmiddle key. • If a split occurred, must insert index entry pointing to L2 into the parent of node L. • Split could propagate all the way up, and cause a split of the root! • To split index node, redistribute entries evenly, but push upmiddle key. (Contrast leaf splits.)

  5. Insertion • Minimum occupancy is guaranteed in both leaf and index pg splits. • Copy-upvs push-up;

  6. Example B+ Tree After Inserting 8* • Root was split, leading to increase in height. • In this example, can avoid split by re-distributing entries

  7. Deletion • 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.

  8. Inserting 8*, Deleting 19* and 20* ... • Deleting 19* is easy. • Deleting 20* is done with re-distribution. Middle key is copied up.

  9. ... And Then Deleting 24* • Must merge. • Observe `toss’ of index entry (on right), and `pull down’ of index entry (below).

  10. Example of Non-leaf Re-distribution • Tree is shown below deletion during of 24*. (What could be a possible initial tree?) • In contrast to previous example, can re-distribute entry from left child of root to right child.

  11. The intuition... • 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.

  12. Issue 1: Fanout • Important to increase fan-out. (Why?) • Index pages can typically hold many more entries than leaf pages. • Search key values in index entries only serve to `direct traffic’; can often compress them without affecting searches. • E.g., If we have adjacent index entries with search key values Dannon , David and Deepak, we can abbreviate David to Dav.

  13. Issue 2: Variable-Size Keys • Variable sized 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. • Order (d) concept replaced by physical space criterion in practice (`at least half-full’).

  14. Issue 3: Bulk Loading • If we have a large collection of records, and we want to create a B+ tree on some field, doing so by repeatedly inserting records is very slow. • Bulk Loadingcan be done much more efficiently. • Initialization: Sort all data entries, insert pointer to first (leaf) page in a new (root) page.

  15. Bulk Loading (Contd.) • Index entries for leaf pages always entered into right-most index page just above leaf level. When this fills up, it splits. (Split may go up right-most path to the root.) • Much faster than repeated inserts, especially when one considers locking!

More Related