简体   繁体   English

分裂B +树根

[英]splitting a B+ tree root

When splitting the root node of a b+ tree I know you take n/2 +1 and make that the new root and split everything accordingly. 拆分b +树的根节点时,我知道您采用n / 2 +1并使其成为新的根并相应地拆分所有内容。

My question lies when n is equal to an odd number. 我的问题是当n等于奇数时。 Like in this case, n = 5 . 像在这种情况下, n = 5

So lets use a simple example: 因此,让我们使用一个简单的示例:

   10  20  30  40 
 /   |   |   |   \

where all of the children are null. 所有的孩子都是空的。 Lets say I want to add 50 to this. 可以说我要加50。

would it look like 看起来像

       30
      /  \
(10,20)   (40,50) 

or 要么

           40
          /  \
 (10,20,30)  (50)

or something different? 还是不同的?

If you split a node that contains n keys - including the incoming key that caused the split - then (n - 1) / 2 keys go to one new child, n - 1 - (n - 1) / 2 go to the other, and one key goes up to the parent level (as separator key). 如果拆分包含节点n键-包括导致分裂进入关键-然后(n - 1) / 2键进入一个新的孩子, n - 1 - (n - 1) / 2转到其他,一个键升至父级(作为分隔键)。 The key that goes up is not necessarily the same as the one that caused the split. 向上的键不一定与引起拆分的键相同。 If there is nowhere for the separator to go up to then you have a new root and the separator key will be its single lone occupant (the minimum occupancy requirement does not apply to root nodes). 如果分隔符无处可去,则您将拥有一个新的根,分隔符将是其唯一的单独占用者(最低占用要求不适用于根节点)。

Of course, the formulae look friendlier if you look at the rest that remains after taking out the new separator: r = n - 1 gives r / 2 for one side and r - r / 2 for the other. 当然,如果看一下取出新分隔符后剩下的其余部分,这些公式看起来会更友好: r = n - 1表示一侧为r / 2 ,另一侧为r - r / 2

In other words, under normal circumstances both 'halves' differ at most by one, which will occur if the total key count is even and hence leaves an odd rest when the separator key is taken out. 换句话说,在正常情况下,两个“半部”最多相差一个,如果总键数为偶数,则会发生这种情况,因此,当取出分隔键时会留下一个奇数的休止符。 It does not matter whether the extra key goes left or right. 左键或右键都无关紧要。

However, this is not hammered in stone. 但是,这并不是一成不变的。 There are other valid redistribution strategies, most notably Knuth's B* where two full nodes make three nodes that are already 2/3rds full, and so on. 还有其他有效的重新分配策略,最著名的是Knuth's B * ,其中两个完整的节点组成三个已经是2 / 3rds完整的节点,依此类推。 This also shows that the split/merge logic is strongly tied to the redistribution measures that do not change the structure, ie donation and borrowing of keys between siblings. 这也表明拆分/合并逻辑与不改变结构的重新分配措施紧密相关,即兄弟姐妹之间密钥的捐赠和借用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM