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