[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Question about MDB_INTEGERKEY flag



Greg Heinrich wrote:
Hello,
sorry for being a noob but I have a question regarding the MDB_INTEGERKEY flag.

I am using the LMDB library through Lua wrappers from
https://github.com/shmul/lightningmdb.

I have an LMDB file which was created with keys that are named "key0",
"key1", ...

When I open the database with mdb_dbi_open(txn, NULL, MDB_INTEGERKEY,
& dbi) and enumerate keys with successive calls to
mdb_cursor_get(cursor, &key, &val, MDB_NEXT) the key values that I
read are the same as in the LMDB (i.e. "key0", ...). Since I am using
the MDB_INTEGERKEY flag I was hoping to read keys as 1,2,3, etc. And I
thought I would then be able to retrieve entries doing e.g.
mdb_get(txn, dbi, "1", &data).

No.

Am I doing anything wrong or is MDB_INTEGERKEY just used to enforce
integer keys when putting entries?

You're doing something wrong.

http://symas.com/mdb/doc/group__mdb__dbi__open.html#ga219c5c50d41902fca79c68d8836e7753

Clearly "key0" is not an integer.

To give my question some background: what I am trying to achieve is to
read entries in my LMDB file in random/arbitrary order. Since I have
may 10 million entries or more, I do not want to store keys in memory.
I'd rather retrieve entries using an index. Is that possible? Note
that I do not have control over the key naming convention so keys
could be named anything.

Sure you can use an index. But you'll have to create it yourself, and map from whatever integer to whatever actual key was used.

Thanks!

Greg.




--
  -- Howard Chu
  CTO, Symas Corp.           http://www.symas.com
  Director, Highland Sun     http://highlandsun.com/hyc/
  Chief Architect, OpenLDAP  http://www.openldap.org/project/