Does LMDB support multiple keys to same value mapping?

和自甴很熟 提交于 2021-01-27 16:33:42

问题


is it possible to have multiple keys mapping to the same value? If not, is there a work around for this feature?


回答1:


It isn't possible. One workaround that I use is to have the value on the second key be a pointer to the primary key. That is, the value of the second key is the primary key.

In particular, I make a secondary-keys table (or "Named Database" in lmdb speak) where all the values are primary keys in the primary table. If you look further into other database this is exactly how they implement indexes.


For example

Data table:
    key: 72E13E60-85A6-4191-A187-F6FA5D3F0975
    value: {
       "surrogate-key": "72E13E60-85A6-4191-A187-F6FA5D3F0975",
       "name": "Foo Widget",
       "location": "Atlantis Mall",
       "last-value": 892
    }
Name table:
    key: "Foo Widget",
    value: "72E13E60-85A6-4191-A187-F6FA5D3F0975"
Location table:
    key: "Atlantis Mall",
    value: "72E13E60-85A6-4191-A187-F6FA5D3F0975"


来源:https://stackoverflow.com/questions/53637169/does-lmdb-support-multiple-keys-to-same-value-mapping

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!