简体   繁体   English

在B Plus树中删除索引后,是否会删除索引中的键?

[英]Will key in the index be removed after deletion in B Plus tree?

I'm a little confused with the deletion in B+ tree. 我对B +树中的删除有些困惑。 I searched a lot in Google and find that there are two implementation when the key you want to delete appears in the index: 我在Google中进行了大量搜索,发现要删除的键出现在索引中时,有两种实现方式:

  1. Delete the key in the index 删除索引中的键
  2. Keep the key in the index 将密钥保留在索引中

Algorithm from https://www.javatpoint.com/b-plus-tree-deletion uses the first way. 来自https://www.javatpoint.com/b-plus-tree-deletion的算法使用第一种方法。

在此处输入图片说明

Algorithm from https://www.cs.princeton.edu/courses/archive/fall08/cos597A/Notes/BplusInsertDelete.pdf uses the second way. 来自https://www.cs.princeton.edu/courses/archive/fall08/cos597A/Notes/BplusInsertDelete.pdf的算法使用第二种方法。

在此处输入图片说明

So I really want to know which one is right. 所以我真的很想知道哪一个是正确的。

But I'm more inclined to take that as an undefined behavior. 但是我更倾向于将其视为未定义的行为。 At this point, could someone help me figure out the advantage and disadvantage between them? 在这一点上,有人可以帮助我找出它们之间的优缺点吗? And how to choose between them? 以及如何在它们之间进行选择?

Thanks in advance. 提前致谢。

Both methods are correct. 两种方法都是正确的。

The difference that you highlight is not so much in deleting/not-deleting internal keys, but in updating/not-updating them. 您突出显示的差异不是删除/不删除内部键,而是更新/不更新它们。

Obviously, when you delete a value (ie a key in a leaf node), the b-plus-tree property is not violated: all child values are still within the range dictated by the parent information. 显然,当您删除一个值(即叶节点中的键)时,不会违反b-plus-tree属性:所有子值都仍在父信息指定的范围内。 You can never break this range-rule by merely removing a value from a leaf. 仅仅从叶子中删除一个值就永远不会破坏这个范围规则。 This rule is also still valid when you update the internal key(s) in the path to that leaf (according to method 1), which is only necessary when the deleted value was the left-most one in its leaf. 当您更新到该叶子的路径中的内部关键字(根据方法1)时,此规则仍然有效,这仅在删除的值是其叶子中最左边的值时才需要。

Note that the two methods may produce quite different trees after a long sequence of the same operations (insert, delete). 请注意,经过长时间的相同操作(插入,删除),这两种方法可能会产生完全不同的树。

But on average the second method will have slightly less work to do. 但是平均而言,第二种方法要做的工作要少一些。 This difference is not significant though. 但是,这种差异并不明显。

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

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