Before understanding this problem, let's first look at the storage structure of the MySQL table, and then compare the differences between binary trees, multi-trees, B trees, and B+ trees. MySQL storage structureTable storage structureUnit: table > segment > area > page > row In the database, whether you read one row or multiple rows, the pages where these rows are located are loaded. That is to say, the basic unit of storage space is page. B+ tree index structure
B+ tree page node structureThere are several characteristics
The main function of a page is to store records, and records are stored in a page in the form of a single linked list. B+ tree retrieval processLet's take a look at the retrieval process of the B+ tree.
Why use B+ tree index? The database accesses data through pages. A page is a B+ tree node. Accessing a node is equivalent to an I/O operation, so the faster the node can be found, the better the search performance. Next, let's compare a binary tree, a multi-fork tree, a B-tree, and a B+ tree. Binary Tree A binary tree is a binary search tree with good search performance, which is equivalent to a binary search. In order to prevent the binary tree from degenerating into a linked list, people invented the AVL tree (balanced binary search tree): the height difference between the left and right subtrees of any node is at most 1. Multi-branch treeA multi-fork tree can have M nodes, which can effectively reduce the height. When the height is reduced, the number of nodes is reduced and the I/O is naturally reduced, and the performance is better than that of a binary tree. B-TreeA B-tree is simply a multi-branch tree, where each leaf stores data and a pointer to the next node. For example, to find 9, the steps are as follows
B+ TreeB+ tree is an improvement of B tree. Simply put, only leaf nodes store data, and non-leaf nodes are storage pointers; all leaf nodes form an ordered linked list. The internal nodes of the B+ tree do not have pointers to the specific information of the keyword, so its internal nodes are smaller than those of the B tree. If all the keywords of the same internal node are stored in the same disk block, the disk block can accommodate more keywords, and the number of keywords that need to be searched at one time is also more, which reduces the relative IO read and write times. For example, to search for keyword 16, the steps are as follows
The difference between B+ tree and B tree:
That’s why MySQL uses B+ trees, it’s that simple! The above is the detailed content of the advantages of using B+ tree index in MySQL. For more information about using B+ tree index in MySQL, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: CSS implementation code for drawing triangles (border method)
Table of contents 1. Computed properties Syntax: ...
According to Chinese custom, we are still celebra...
Table of contents The basic concept of modularity...
Overview Today we will mainly share how to config...
Introduction Incremental backup means that after ...
Development Background: Recently, I am working on...
Table of contents react-native project initializa...
1. Dynamic parameters Starting from 2.6.0, you ca...
This article example shares the specific code of ...
Introduction MySQL provides an EXPLAIN command th...
Event bubbling, event capturing, and event delega...
This article shares with you the specific method ...
question Running gdb in docker, hitting a breakpo...
Excel export always fails in the docker environme...
As the platform continues to grow, the project...