Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top