Has LevelDB keys a limit for the key length?
I want to save data with url's as key. so this urls can be very very long i.g. http://veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryloooooooooooooooong-url.com
LevelDB is an on-disk key-value store where the keys and values are both arbitrary blobs of data. Each LevelDB database occupies a folder on the file system. The folder will contain some combination of files named “CURRENT”, “LOCK”, “LOG”, “LOG. old” and files named “MANIFEST-######”, “######.
There is no key length limit in LevelDB. Keys are arbitrary byte arrays of any length. You can use a long url like you've provided in your question.
They mention here that the keys are byte arrays... https://code.google.com/p/leveldb/
As a test, I inserted some documents with keys that were a million characters long. It worked just fine.
There is no theoretical limit to the key length, but the DB might not be very efficient with long keys and short records. There is an index at the top of the SST files that contains the keys and the offsets into the file, and the keys in these index blocks are binary chopped to locate rows.
Just a thought - you might want to do some sanitisation on the URLs before using them as raw keys. e.g., canonicalise the domain name and case of the protocol, canonicalise the order of the query params, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With