Comic: What is a B+ tree?
In the last comic, we introduced the principle and application of B-tree. Those who have not read it can click on the link below:
Comic: What is a B-tree?
This time we will introduce the B+ tree.
—————————————————
A B-tree of order m has the following characteristics:
1. The root node has at least two children.
2. Each intermediate node contains k-1 elements and k children, where m/2 <= k <= m
3. Each leaf node contains k-1 elements, where m/2 <= k <= m
4. All leaf nodes are located on the same layer.
5. The elements in each node are arranged from small to large, and the k-1 elements in the node are exactly the range divisions of the elements contained in the k children.
A B+ tree of order m has the following characteristics:
1. The intermediate node with k subtrees contains k elements (k-1 elements in the B tree), and each element does not store data, but is only used for indexing, and all data is stored in leaf nodes.
2. All the leaf nodes contain the information of all the elements, and the pointers to the records containing these elements, and the leaf nodes themselves are linked in order of the size of the keyword from small to large.
3. All intermediate node elements exist in child nodes at the same time, and are the largest (or smallest) element among the child node elements.
Satellite Information in the B-tree (Satellite Information):
Satellite information in the B+ tree (Satellite Information):
What needs to be added is that in the clustered index (Clustered Index) of the database, the leaf nodes directly contain satellite data. In a non-clustered index (NonClustered Index), leaf nodes have pointers to satellite data.
The first disk IO:
The second disk IO:
The third disk IO:
B-tree range search process
From top to bottom, find the lower limit of the range (3):
Traverse to element 6 in middle order:
Traverse to element 8 in middle order:
Traverse to element 9 in middle order:
The middle order traverses to element 11, and the traversal ends:
B+ tree range search process
From top to bottom, find the lower limit of the range (3):
Traverse to elements 6, 8 through the linked list pointer:
Through the linked list pointer, traverse to elements 9, 11, and the traversal ends:
Features of B+ tree:
1. The intermediate node with k subtrees contains k elements (k-1 elements in the B tree), and each element does not store data, but is only used for indexing, and all data is stored in leaf nodes.
2. All the leaf nodes contain the information of all the elements, and the pointers to the records containing these elements, and the leaf nodes themselves are linked in order of the size of the keyword from small to large.
3. All intermediate node elements exist in child nodes at the same time, and are the largest (or smallest) element among the child node elements.
Advantages of B+ tree:
1. A single node stores more elements, resulting in fewer IO queries.
2. All queries must find leaf nodes, and the query performance is stable.
3. All leaf nodes form an ordered linked list, which is convenient for range query.
—————END—————
Friends who like this article, please press and hold the picture to follow the subscription account and dream about it and watch more exciting content