In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What is the reason why Mysql chooses B+ tree, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
Let's answer from the perspective of data structure.
You should know that one of the most important differences between B-trees and B + trees is
In the B+ tree, only the leaf nodes store data, and the rest of the nodes are used for indexing.
The B-tree is that every Inode has a data domain.
This determines that the B+ tree is more suitable for storing external data, the so-called disk data.
From the perspective of Mysql (Inoodb)
The B + tree is used to act as an index. Generally speaking, the index is very large, especially the relational database, which has a large amount of data.
So in order to reduce the footprint of memory, the index is also stored on disk.
So how does Mysql measure query efficiency?
All the Data domains of the B+ tree are on the leaf node.
In this way, you can get all the data by traversing the leaf nodes, so that you can have interval access.
Generally speaking, there is an optimization, that is, all the leaf nodes are strung together with pointers.
To put it bluntly, increase the number of disk IO.
The amount of data read out by disk IO at one time is fixed. When a single data becomes larger, less data is read each time, and the number of IO increases. How time-consuming an IO is! ),
Disk IO times, B-tree (class B tree) is specific is that the number of nodes per layer is very large, the number of layers is very small, the purpose is to reduce the number of disk IO.
When querying data, the best case is to find the target index quickly, and then read the data, which can be well accomplished by using B + tree.
But every node of the B-tree has a data domain (pointer), which undoubtedly increases the node size.
The B+ tree does not store data except the leaf node. If the node is small, the number of disk IO is less.
This is one of the advantages.
What's another advantage?
As to why MongoDB uses B-trees instead of B + trees
It is not a traditional relational database, but a nosql stored in Json format.
The goal is high performance, high availability, and easy scalability.
First of all, it got rid of the relational model.
Secondly, due to the use of B + tree in Mysql, the data is on the leaf node, and each query needs to access the leaf node.
MongoDB uses a B-tree, and all nodes have Data domains.
The demand for advantage 2 mentioned above is not so strong.
Access can be made as long as the specified index is found, and there is no doubt that a single query is on average faster than Mysql (but at least from the side of Mysql, the average query time is about the same).
Can be considered from the point of view of its design.
Generally speaking, Mysql chooses B + tree and MongoDB chooses B-tree according to its own needs.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.