简体   繁体   中英

B+ tree and secondary index

I was wondering how B+ trees that use secondary indexing work? 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. In B+ trees you keep keys and pointers to data only in leaf-nodes, and they might be duplicates. 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.

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      |
        ---------    ---------

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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