Comic: What is a B+ tree?

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.

—————————————————
Comic: What is a B+ tree?

Comic: What is a B+ tree?
Comic: What is a B+ tree?

Comic: What is a 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.
Comic: What is a B+ tree?

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.

Comic: What is a B+ tree?
Comic: What is a B+ tree?

Comic: What is a B+ tree?

Comic: What is a B+ tree?
Comic: What is a B+ tree?
Comic: What is a B+ tree?

Comic: What is a B+ tree?

Comic: What is a B+ tree?

Comic: What is a B+ tree?
Comic: What is a B+ tree?

Comic: What is a B+ tree?

Comic: What is a B+ tree?

Comic: What is a B+ tree?
Comic: What is a B+ tree?

Satellite Information in the B-tree (Satellite Information):
Comic: What is a B+ tree?

Comic: What is a B+ tree?

Satellite information in the B+ tree (Satellite Information):
Comic: What is a B+ tree?

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.
Comic: What is a B+ tree?
Comic: What is a B+ tree?
Comic: What is a B+ tree?

The first disk IO:
Comic: What is a B+ tree?

The second disk IO:
Comic: What is a B+ tree?

The third disk IO:
Comic: What is a B+ tree?

Comic: What is a B+ tree?

Comic: What is a B+ tree?
Comic: What is a B+ tree?

Comic: What is a B+ tree?

Comic: What is a B+ tree?

Comic: What is a B+ tree?

B-tree range search process

From top to bottom, find the lower limit of the range (3):
Comic: What is a B+ tree?

Traverse to element 6 in middle order:
Comic: What is a B+ tree?

Traverse to element 8 in middle order:
Comic: What is a B+ tree?

Traverse to element 9 in middle order:
Comic: What is a B+ tree?

The middle order traverses to element 11, and the traversal ends:
Comic: What is a B+ tree?
Comic: What is a B+ tree?

Comic: What is a B+ tree?

B+ tree range search process

From top to bottom, find the lower limit of the range (3):

Comic: What is a B+ tree?

Traverse to elements 6, 8 through the linked list pointer:
Comic: What is a B+ tree?

Through the linked list pointer, traverse to elements 9, 11, and the traversal ends:
Comic: What is a B+ tree?

Comic: What is a B+ tree?

Comic: What is a B+ tree?

Comic: What is a B+ tree?

Comic: What is a B+ tree?

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.
Comic: What is a B+ tree?

—————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

Comic: What is a B+ tree?

Guess you like

Origin blog.51cto.com/14982143/2550950