简体   繁体   English

B +树和二级索引

[英]B+ tree and secondary index

I was wondering how B+ trees that use secondary indexing work? 我想知道使用二级索引的B +树如何工作? With the secondary indexing, the tree can have duplicate values in its leaf nodes. 通过二级索引,该树在其叶节点中可以具有重复的值。 When an insertion occurs, how does the tree know where to but the record if their are duplicate values for the field it is inserting on? 发生插入时,树如何知道要插入的位置(如果它们是要插入的字段的重复值)呢?

This article suggests a good approach to handling duplicate keys in B+ tree. 本文提出了一种处理B +树中重复键的好方法。 In B+ trees you keep keys and pointers to data only in leaf-nodes, and they might be duplicates. 在B +树中,仅将数据的键和指针保留在叶节点中,它们可能是重复的。 For example, 7 7 7. To find them you also keep a key 7 in interior node (below), right pointer references the block with the keys that >= 7, that is, block with the those 3 keys. 例如,7 77。要找到它们,您还需要在内部节点(下面)中保留一个键7,右指针使用> = 7的键引用该块,即使用这3个键的块。

Now, on insert, there might be a situation new duplicate key does not fit the node and in order to be balanced tree would have to be reorganized. 现在,在插入时,可能会出现新的重复密钥不适合该节点的情况,为了平衡树,必须重新组织。 But it is costly, so the author suggests adding an overflow block and linking it to that one which contains duplicated keys. 但这是昂贵的,因此作者建议添加一个溢出块并将其链接到包含重复密钥的那个块。

------------
| 5 | 7 |  |
V---V---V---
        ---------    ---------
        |7  7  7| -> |7      |
        ---------    ---------

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

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