Does LevelDB have a maximum length limit for keys?

Does LevelDB have a key length limit?

I want to save data with url as a key. therefore these urls can be very long ig http://veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryloooooooooooooooong-url.com

+7
source share
2 answers

LevelDB does not have a key length limit. The keys are arbitrary byte arrays of any length. You can use a long url as you indicated in your question.

It is mentioned here that the keys are byte arrays ... https://code.google.com/p/leveldb/

As a test, I inserted a few documents with keys a million characters long. Everything went perfectly.

+7
source

There is no theoretical limit for the key length, but the database may not be very effective with long keys and short records. At the top of the SST files there is an index that contains keys and offsets in the file, and the keys in these blocks of the index are binary to find strings.

Just think - you can do some sanitation on the URLs before using them as raw keys. for example, canonicalize the domain name and protocol case, canonicalize the order of the request parameters, etc.

0
source

All Articles