首页 新闻 会员 周边

MongoDB 的索引到底是使用 B+ 树还是 B 树

0
悬赏园豆:50 [待解决问题]

我在本篇就提出了个问题:https://www.cnblogs.com/everlose/p/12825672.html

简单描述下,根据官网的说法是 B 树,

但是有个帖子里的人说他问过引擎作者,回答是 B+ 树,虽然官网写着 B 树。这个信息相关的佐证又很难找。

有没有知道的大佬能解答下,不胜感激。

Ever-Lose的主页 Ever-Lose | 初学一级 | 园豆:164
提问于:2020-05-08 22:43
< >
分享
所有回答(2)
0

B+树是一种B树吧,所以官方说的也对

会长 | 园豆:12401 (专家六级) | 2020-05-09 09:50
0

我没有看过源码,不过从官方介绍以及B+Tree的优点来看,应该是 B+Tree

相信你看过B+tree相对于B-tree的优化了,那么对于大数据量的存储来讲,B+tree是更合适的。

官方文档有介绍,3.2版本及以后,MongoDB的存储引擎为WiredTiger,而WiredTiger采用的数据结构就是B+Tree。参考链接:MongoDB存储引擎说明,以及 WiredTiger官方介绍

Before detailing each page size, here is a review of how data gets stored inside WiredTiger:

  • WiredTiger uses the physical disks to store data durably, creating on-disk files for the tables in the database directory. It also caches the portion of the table being currently accessed by the application for reading or writing in main memory.
  • WiredTiger maintains a table's data in memory using a data structure called a B-Tree ( B+ Tree to be specific), referring to the nodes of a B-Tree as pages. Internal pages carry only keys. The leaf pages store both keys and values.

我感觉之所以网上有一些讨论说XX为什么使用B+Tree而不是B-Tree,原因在于B+Tree本身就是B-Tree的一个优化变种,官方并没有强调具体使用的哪个B-Tree的子类。而很些人就抓住官方的未明确的介绍开始分析“为什么mysql使用B+Tree而MongoDB使用B-Tree?”,私以为他们也并没有看过源码。。。

当然,我说了我也只是看了文档,到底对不对,我觉得最终的答案是,去看你需要的版本的MongoDB源码 😄。

。淑女范erり | 园豆:961 (小虾三级) | 2020-05-09 10:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册