database - 理解B+树插入

标签 database algorithm indexing b-tree

我正在尝试按以下顺序创建一个 B+ 树,

10 20 30 40 50 60 70 80 90 100

所有 inode 应该有最少 2 个和最多 3 个键。我能够插入到 90,但是一旦插入 100,它的高度就会从 2 增加到 3。

问题是 root 的第二个 child 有一个节点,我无法修复它。它应该至少有 2 个,对吧?有人可以指导我吗?

更新:我遵循这个算法

If the bucket is not full (at most b - 1 entries after the insertion), add the record.
Otherwise, split the bucket.
Allocate new leaf and move half the bucket's elements to the new bucket.
Insert the new leaf's smallest key and address into the parent.
If the parent is full, split it too.
Add the middle key to the parent node.
Repeat until a parent is found that need not split.
If the root splits, create a new root which has one key and two pointers. (That is, the value that gets pushed to the new root gets removed from the original node)

P.S:我是手工做的,亲手做的,为了理解算法。没有密码!

最佳答案

我相信你的B+树是O.K,假设你的B+树的阶数是3。如果阶数是m,每个内部节点可以有⌈m/2⌉m 个 child 。在您的情况下,每个内部节点可以有 2 到 3 个子节点。在 B+ 树中,如果一个节点只有 2 个子节点,那么它只需要 1 个键,因此 B+ 树不会违反任何约束。

如果你还一头雾水,看这个B+ Tree Simulator .试试吧。

关于database - 理解B+树插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16066064/

相关文章:

mysql - SQL 选择某一列中具有最高值的前 3 行

algorithm - 使用预定义的排序值列表对对象进行排序

ios - 以编程方式在 plist 文件中添加索引

MySQL : Storing business logic in table

sql - 有人可以解释一下吗

sql - SQL GROUP BY 字段在所有情况下都是可交换的吗?

SQL Server 索引性能 - 长列

python - 获取已打印python的文本内容

algorithm - 就计算复杂度而言,Big O 表示法 O(log n) 与 O(n+log n) 相同吗?

mysql - order by 导致查询执行速度大大减慢