Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Database Systems1 B+-Trees Storage Technology: Topic 5.

Similar presentations


Presentation on theme: "Introduction to Database Systems1 B+-Trees Storage Technology: Topic 5."— Presentation transcript:

1 Introduction to Database Systems1 B+-Trees Storage Technology: Topic 5

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

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

4 Introduction to Database Systems4 Insertion v Start at root, find leaf L where entry belongs. v 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. u Redistribute entries evenly, copy up middle key. v If a split occurred, must insert index entry pointing to L2 into the parent of node L. v Split could propagate all the way up, and cause a split of the root! –To split index node, redistribute entries evenly, but push up middle key. (Contrast leaf splits.)

5 Introduction to Database Systems5 Insertion v Minimum occupancy is guaranteed in both leaf and index pg splits. v Copy-up vs push-up ;

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

7 Introduction to Database Systems7 Deletion v Start at root, find leaf L where entry belongs. v Remove the entry. –If L is at least half-full, done! –If L has only d-1 entries, u Try to re-distribute, borrowing from sibling (adjacent node with same parent as L). u If re-distribution fails, merge L and sibling. v If merge occurred, must delete entry (pointing to L or sibling) from parent of L. v Merge could propagate to root, decreasing height.

8 Introduction to Database Systems8 Inserting 8*, Deleting 19* and 20*... v Deleting 19* is easy. v Deleting 20* is done with re-distribution. Middle key is copied up.

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

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

11 Introduction to Database Systems11 The intuition... v Entries are re-distributed by ` pushing through ’ the splitting entry in the parent node. v It suffices to re-distribute index entry with key 20; we’ve re-distributed 17 as well for illustration.

12 Introduction to Database Systems12 Issue 1: Fanout v Important to increase fan-out. (Why?) v Index pages can typically hold many more entries than leaf pages. v 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 Introduction to Database Systems13 Issue 2: Variable-Size Keys v Variable sized search keys mean different nodes will contain different numbers of entries. v Even with fixed length fields, multiple records with the same search key value ( duplicates ) can lead to variable-sized data entries. v Order ( d ) concept replaced by physical space criterion in practice (` at least half-full ’).

14 Introduction to Database Systems14 Issue 3: Bulk Loading v 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. v Bulk Loading can be done much more efficiently. v Initialization : Sort all data entries, insert pointer to first (leaf) page in a new (root) page.

15 Introduction to Database Systems15 Bulk Loading (Contd.) v 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.) v Much faster than repeated inserts, especially when one considers locking!


Download ppt "Introduction to Database Systems1 B+-Trees Storage Technology: Topic 5."

Similar presentations


Ads by Google