B Trees and B Trees
B Trees and B Trees
Preview
B-Tree Indexing B-Tree B-Tree Characteristics B-Tree Example B+-Tree B+-Tree Characteristics B+-Tree Example
B-Tree Index
Standard use index in relational databases in a B-Tree
index. Allows for rapid tree traversal searching through an upside-down tree structure Reading a single record from a very large table using a B-Tree index, can often result in a few block reads even when the index and table are millions of blocks in size. Any index structure other than a B-Tree index is subject to overflow.
Overflow is where any changes made to tables will not have records added into the original index structure, but rather tacked on the end.
What is a B-Tree?
B-tree is a specialized multiway tree
designed especially for use on disk. B-Tree consists of a root node, branch nodes and leaf nodes containing the indexed field values in the ending (or leaf) nodes of the tree.
B-Tree Characteristics
In a B-tree each node may contain a large number of
keys B-tree is designed to branch out in a large number of directions and to contain a lot of keys in each node so that the height of the tree is relatively small Constraints that tree is always balanced Space wasted by deletion, if any, never becomes excessive Insert and deletions are simple processes
Complicated only under special circumstances -Insertion into a node that is already full or a deletion from a node makes it less then half full
B-Tree Insertion
1)
2) 3) 4)
B-tree starts with a single root node (which is also a leaf node) at level 0. Once the root node is full with p 1 search key values and when attempt to insert another entry in the tree, the root node splits into two nodes at level 1. Only the middle value is kept in the root node, and the rest of the values are split evenly between the other two nodes. When a nonroot node is full and a new entry is inserted into it, that node is split into two nodes at the same level, and the middle entry is moved to the parent node along with two pointers to the new split nodes. If the parent node is full, it is also split. Splitting can propagate all the way to the root node, creating a new level if the root is split.
5) 6)
B-Tree Deletion
1) If deletion of a value causes a node to be less
than half full, it is combined with it neighboring nodes, and this can also propagate all the way to the root. - Can reduce the number of tree levels.
*Shown by analysis and simulation that, after numerous random insertions and deletions on a B-tree, the nodes are approximately 69 percent full when the number of values in the tree stabilizes. If this happens , node splitting and combining will occur only rarely, so insertion and deletion become quite efficient.
children and 4 keys All nodes other than the root must have a minimum of 2 keys The first 4 letters get inserted into the same node
order), which happens to be W. Move W up to replace the T. That way, what we really have to do is to delete W from the leaf .
proper leaf. If a target key is less than a key in an internal node, then the pointer just to its left is followed. If a target key is greater or equal to the key in the internal node, then the pointer to its right is followed. B+ Tree combines features of ISAM (Indexed Sequential Access Method) and B Trees.
allows the data file to exist separately from the B+ tree, which functions as an "index" giving an ordering to the data in the data file.
redistributed from the node on the left because it is full. The parent node is adjusted to reflect the change.
References
Beginning Database Design By Gavin Powell Database System Concepts By Silberschatz,