Closed tpunder closed 6 months ago
@Kerollmops I think longer-keys
makes sense since you don't get unlimited key sizes. The actual max key length is architecture dependent (related to the page size). I've seen values of 8126 bytes on my M1 Macbook Pro and 1982 bytes on my Intel Macbook Pro.
I've updated the PR to include the rename. I've also hooked up the mdb_env_get_maxkeysize
function (as Env::max_key_size()
) so people have a way to check what the value is for them. I've also updated the docs a bit.
It's not clear to me that using longer-keys
actually increases the overhead (e.g. length bytes) of any data stored on disk. It looks like a short
is always used for the key length of a node: https://github.com/LMDB/lmdb/blob/88d0531d3ec3a592cdd63ca77647d31c568c24bc/libraries/liblmdb/mdb.c#L1124
I think the database/file format is the same regardless of the MDB_MAXKEYSIZE
.
I think the only real downsize would be that the database files become potentially non-portable across architectures with different page sizes if you are actually storing long keys. For example: If I create a database on my M1 Macbook Pro (key length limit of 8126 bytes) with a key of size 2000 bytes and then try to open that file on my Intel Macbook pro (key length limit 1982) then I think I would have problems. However, if all of my keys are under 1982 bytes then I don't think there is any problem.
@Kerollmops I added a note about moving databases between different architectures to the feature flag. I think I also got your proposed changes from above.
@Kerollmops No, when using the DUPSORT
feature the data length is restricted to 8192/1982 bytes (or whatever it is for your architecture). DUPSORT
values are stored as keys of a sub-db which means they must meet any key length limits.
@Kerollmops I just ran cargo +nightly fmt
to fix the formatting in lmdb_ffi.rs
. Hopefully all is good now 😀
This PR (which does not have a corresponding issue) adds a
longer-keys
feature tolmdb-master-sys
andheed
which sets-DMDB_MAXKEYSIZE=0
when compiling LMDB. This allows you to use keys that are larger than the default of 511 bytes long.The feature is 100% opt-in.
I've added a conditional test to
lmdb-master-sys
andheed
to check that keys larger than 511 can be successfully stored without returning anMDB_BAD_VALSIZE
error.Enabling this feature also allows you to use values larger than 511 in databases with the
MDB_DUPSORT
flag set (which was the problem I was running into).Here is the documentation snippet from http://www.lmdb.tech/doc/group__internal.html: