1 / 17

B + -Tree Index Files

B + -Tree Index Files. Takahiko Saito. Introduction. The most widely used of several index structures that maintain efficiency despite insertion and deletion Takes the form of a balanced tree in which every path from the root of the tree to a leaf of the tree is of the same length.

lelia
Download Presentation

B + -Tree Index Files

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+-Tree Index Files Takahiko Saito

  2. Introduction • The most widely used of several index structures that maintain efficiency despite insertion and deletion • Takes the form of a balanced tree in which every path from the root of the tree to a leaf of the tree is of the same length

  3. Example of B+-Tree

  4. Typical node of a B+-Tree • Up to n-1 search key values K1, K2, … , Kn-1 • Search-key values within a node are kept in sorted order • Up to n pointers P1, P2, … , Pn

  5. Leaf Nodes in B+-Trees • Pi either points to • a file record with search-key value Ki, or • to a bucket of pointers to file records, each record having search-key value Ki

  6. Leaf Nodes in B+-Trees (cont) • Hold up to n-1 values • Contain as few as (n-1)/2 values • The ranges of values in each leaf do not overlap • If Li, Lj are leaf nodes and i < j, Li’s search-key values are less than Lj’s search-key values

  7. Non-Leaf Nodes in B+-Trees • Form a multilevel index on the leaf nodes • Hold up to n pointers • Must hold at least (n/2) pointers • The root can hold fewer than (n/2) pointers, but it must hold at least 2 pointers

  8. Queries on B+-Trees • Start with the root node • Examine the node for the smallest search-key value > k. • If such a value exists, assume it is Kj. Then follow Pi to the child node • Otherwise k Km–1, where there are m pointers in the node. Then follow Pm to the child node. • If the node reached by following the pointer above is not a leaf node, repeat the above procedure on the node, and follow the corresponding pointer. • Eventually reach a leaf node. If for some i, key Ki = k follow pointer Pito the desired record or bucket. Else no record with search-key value k exists.

  9. Insertion on B+-Trees • Find the leaf node in which the search-key value would appear • If the search-key value is already there in the leaf node, record is added to file and if necessary a pointer is inserted into the bucket. • If the search-key value is not there, then add the record to the main file and create a bucket if necessary. Then: • If there is room in the leaf node, insert (key-value, pointer) pair in the leaf node • Otherwise, split the node (along with the new (key-value, pointer) entry) as discussed in the next slide.

  10. Insertion on B+-Trees (cont.) • Splitting a node: • take the n(search-key value, pointer) pairs (including the one being inserted) in sorted order. Place the first  n/2 in the original node, and the rest in a new node. • let the new node be p, and let k be the least key value in p. Insert (k,p) in the parent of the node being split. If the parent is full, split it and propagate the split further up.

  11. Example of Insertion on B+-Trees

  12. Deletion on B+-Trees • Find the record to be deleted, and remove it from the main file and from the bucket (if present) • Remove (search-key value, pointer) from the leaf node if there is no bucket or if the bucket has become empty

  13. Deletion on B+-Trees (cont.)

  14. Deletion on B+-Trees (cont.) • If the node has too few entries due to the removal, and the entries in the node and a sibling fit into a single node, then • Insert all the search-key values in the two nodes into a single node (the one on the left), and delete the other node. • Delete the pair (Ki–1, Pi), where Pi is the pointer to the deleted node, from its parent, recursively using the above procedure.

  15. Deletion on B+-Trees (cont.) • if the node has too few entries due to the removal, but the sibling already contains the maximum number of pointers, then • Redistribute the pointers between the node and the sibling such that both have more than the minimum number of entries. • Update the corresponding search-key value in the parent of the node.

  16. Deletion on B+-Trees (cont.)

  17. Reference • Database System Concepts • www.csee.umbc.edu/~pmundur/courses/CMSC461-05/ch12.ppt

More Related