-
-
Notifications
You must be signed in to change notification settings - Fork 25
feat: Prefix Bloom Filter #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
dc3bbca
to
4d4941d
Compare
/// Checks if a key is in domain and prefix can be extracted from it. | ||
/// For example if `PrefixExtractor` suppose to extract first 4 bytes from key, | ||
/// `in_domain(&[0, 2, 3])` should return false | ||
fn in_domain(&self, key: &[u8]) -> bool; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is necessary.
If a key is [1, 2, 3] and we extract the first 4 bytes, we would just take the entire string, so:
let len = Math.min(key.len(), 4);
return key.slice(0, len);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me better explain why is this needed in more practical example:
Imagine we have a database where keys are constructed using the following template: {datatype}#{id}
and a prefix extractor that would extract {datatype}#
prefix from a key to optimize scans of all rows of datatype#
. Then, in table were populated following rows table1#a
, table1#b
, table2#a
. The keys for bloom filter would be table1#
, table2#
in this case. Then, if we use prefix scan by prefixes table1#
or table2#
everything will work correctly. But if scan is performed with table
prefix without in_domain
the full prefix will be extracted and will try to check bloom filter by table
key, which may return false negative. in_domain
in this case will help to prevent such cases and will use Bloom Filter only in case when prefix is in domain. In this example everything starting with {datatype}#
will be considered as in_domain
and use Bloom Filter, other prefixes will be not in_domain
and will just use normal prefix search ignoring Bloom Filter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
However, for the prefix extractor to support structured prefixes, the trait needs to return an Iterator over extracted prefixed (see #97 and fjall-rs/fjall#116). At that point, the trait could just return std::iter::empty
, which would signal that the key is "not in domain".
For example we may extract prefixes, like:
eu#germany#berlin
-> extract "eu#" as prefix
-> also extract "eu#germany#"
Now prefix searches over both continent and [continent + country] can be filtered by the prefix filter.
This PR supposed to resolve #97
Please, let me know if I missed something.