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)
NERDTree is a file system browser for Vim. With t...
Uninstall the old version of MySQL (skip this ste...
If you forget your MySQL login password, the solu...
The isnull() function cannot be used as a substit...
Async Hooks is a new feature of Node8. It provide...
This article shares the specific code of JavaScri...
1. Make a repo file Refer to the official install...
This article is an integrated article on how to c...
Preface In Java programming, most applications ar...
For those who are new to virtual machines or have...
1. First, you need to know what will trigger the v...
Today I saw a little trick for HTML text escaping ...
This article records the installation tutorial of...
1. Introduction Git is a free, open source distri...
Add the jvm.options file to the elasticsearch con...