rocksdb icon indicating copy to clipboard operation
rocksdb copied to clipboard

Support 'prefix_extractor' option?

Open webbery opened this issue 5 years ago • 5 comments

I look at the source code and find none about 'prefix_extractor'. Will rocksdb support 'prefix_extractor' option?

webbery avatar May 08 '20 07:05 webbery

A PR is welcome. I don't know what prefix_extractor is and what kind of API it would require, so it'd be best to discuss that before opening a PR, so that we can assess the complexity.

vweevers avatar May 10 '20 06:05 vweevers

From the looks of things there are three options, via classes:

  • FixedPrefixTransform takes integer opt
  • CappedPrefixTransform takes integer opt
  • SamePrefixTransform takes string opt

Not sure whether SamePrefixTransform is enabled - its hidden behind a GFLAGS macro check, which is not defined according to my vscode. Its also in a test file - prefix_test.cc

presumably this could be exposed to the js side as

options: {
  ...
  prefix_extractor? : {
    fixed?: number,
    capped?: number,
    same?: string
  } 
}

where ? is optional notation and only 1 of them should be be defined.

on the binding side (db_open), it would require checking which is defined (if any), and mapping to the corresponding class;

i.e.

options.prefix_extractor.reset(NewFixedPrefixTransform(2));

before being sent to the open the db.

MeirionHughes avatar Apr 22 '21 21:04 MeirionHughes

What does it do?

vweevers avatar Apr 22 '21 22:04 vweevers

Not 100% sure - but it seems it can optimize seeking/iterating when you're doing composite keys. https://github.com/facebook/rocksdb/wiki/Prefix-Seek#defining-a-prefix

MeirionHughes avatar Apr 22 '21 22:04 MeirionHughes

I don't need this tbh - but I fancied having a gander at the code-base and tried to add it. #168

MeirionHughes avatar Apr 22 '21 23:04 MeirionHughes