Skip to content

Conversation

khlopkov
Copy link

This PR supposed to resolve #97

Please, let me know if I missed something.

@khlopkov khlopkov force-pushed the feat/prefix_bloom_filter branch from dc3bbca to 4d4941d Compare January 18, 2025 14:16
/// 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;
Copy link
Contributor

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);

Copy link
Author

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

Copy link
Contributor

@marvin-j97 marvin-j97 Jan 20, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prefix bloom filters
2 participants