user2584960
user2584960

Reputation: 695

Does LMDB support multiple keys to same value mapping?

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

Upvotes: 3

Views: 1531

Answers (1)

Michael Deardeuff
Michael Deardeuff

Reputation: 10697

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"

Upvotes: 1

Related Questions