简体   繁体   English

为什么我们不将父指针保存在B +树中以便在树中轻松向上遍历?

[英]why we are not saving the parent pointer in B+ Tree for easy upward traversal in tree?

Will it affect much if I add a pointer to the parent Node to get simplicity during splitting and insertion process. 如果在拆分和插入过程中添加指向父节点的指针以简化操作,这会影响很多。 General Node would then look something like this- 然后,通用节点将看起来像这样-

class BPTreeNode{
    bool leaf;
    BPTreeNode *next;
    BPTreeNode *parent; //add-on
    std::vector < int* >pointers;
    std::vector < int >keys;
};

What are the challenges I might get in real life database system since right now I am only implementing it as a hobby project? 既然我现在只是将它作为一个业余项目实施,那么在现实生活中的数据库系统可能会遇到哪些挑战?

There are two reasons I can think of: 我可以想到两个原因:

  1. The algorithm for deleting a value from a B+tree may result in an internal block A that has too few child blocks. 从B +树中删除值的算法可能会导致内部块A的子块太少。 If neither the block at the left or right of A can pass an entry to A in order to resolve this violation, then block A needs to merge into a sibling block B. This means that all the child blocks of block A need to have their parent pointer updated to block B. This is additional work that increases (a lot) the number of blocks that need an update in a delete-operation. 如果A左边或右边的块都不能将条目传递给A来解决此冲突,则块A需要合并为同级块B。这意味着块A的所有子块都需要具有它们的子块。父指针已更新为块B。这是一项额外的工作,在删除操作中需要增加(很多)块的数量。

  2. It represents extra space that is really not needed for performing the standard B+Tree operations. 它代表执行标准B + Tree操作实际上并不需要的额外空间。 When searching a value via a B+Tree you can easily keep track of the path to that leaf level and use it for backtracking upwards in the tree. 通过B + Tree搜索值时,您可以轻松地跟踪到该叶级别的路径,并将其用于在树中向上回溯。

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

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