feat(store): add key_prefix_from cursor to Query for efficient prefix scans - #108
Open
royalcala wants to merge 2 commits into
Open
feat(store): add key_prefix_from cursor to Query for efficient prefix scans#108royalcala wants to merge 2 commits into
royalcala wants to merge 2 commits into
Conversation
Adds an optional field to the Query struct that serves as a cursor position for prefix scans. When set together with a KeyFilter::Prefix, the B-tree seek starts at the cursor position instead of the prefix start, enabling efficient iteration over large datasets from a known position. - Add to Query and QueryBuilder - Add builder method - Pass cursor through IndexKind::KeyAuthor to ByKeyBounds - Use cursor as lower bound for B-tree range scan (O(log n))
- Add unit test for ByKeyBounds with cursor lower bound - Add debug_assert that cursor starts with prefix - Document SortBy::KeyAuthor requirement in doc comment - Document that from is ignored on AuthorKey index path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional
fromcursor field to theQuerystruct that enables B-tree-level seeks during prefix scans.Motivation
The current
key_prefixfilter always starts iteration from the beginning of the prefix range. For applications maintaining a cursor position (e.g., syncing event logs), this forces O(n) client-side skipping viaoffset. With this change, the B-tree seeks directly to the cursor position in O(log n).Changes
from: Option<Bytes>field toQueryandQueryBuilder(store.rs)key_prefix_from(prefix, from)builder method (store.rs)IndexKind::KeyAuthortoByKeyBounds::new(util.rs,bounds.rs,query.rs)fromis set with aPrefixfilter, the lower bound becomes the cursor position instead of the prefix startBackward Compatibility
Fully backward-compatible. When
fromisNone(default), behavior is identical to currentkey_prefix. The wire format adds an optional field that defaults toNone.Usage