isamu / rocksdb-ruby

A simple RocksDB library for Ruby
MIT License
75 stars 24 forks source link

Integer keys and key ranges #31

Open collimarco opened 2 years ago

collimarco commented 2 years ago

Hello,

Thanks for this interesting project!

I am new to rocksdb and I am wondering if I can use integer keys and then get a range of keys (something like 10 < key < 200).

I see that there is a method each_range, however it seems to work only for text (lexicographical order).

Is there any way to query with numbers (less than, greater than, between) in an efficient way?

katafrakt commented 2 years ago

I haven't used RocksDB in a while, but I don't think it's possible. The keys are just assumed to be strings. There is some discussion about improving on that outlined here: https://github.com/facebook/rocksdb/wiki/Open-Projects#time-series-dbs

collimarco commented 2 years ago

I was thinking about converting numbers to strings of the same length in big endian, for example:

0000000000
0000000001
0000000002
...
0000000010
0000000011
0000000012

This should produce the right order even if you waste some extra bytes.

However I still wonder if the performance of rocksdb are good when you need to search on a range.