perf(index): use NGram posting cardinalities for regex conjunction search#7390
Open
everySympathy wants to merge 1 commit into
Open
perf(index): use NGram posting cardinalities for regex conjunction search#7390everySympathy wants to merge 1 commit into
everySympathy wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
807c6d9 to
59187b6
Compare
59187b6 to
1e33ff5
Compare
1e33ff5 to
b1ba3f9
Compare
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
This PR improves regex conjunction search on the NGram index by making posting-list evaluation more cost-aware.
The existing regex NGram acceleration can derive required trigrams from regex patterns, but conjunction queries may still load and intersect posting lists without considering posting-list size. This PR adds posting-list cardinality metadata and uses rare-first ordering to reduce unnecessary work, especially when a required trigram is missing or when a regex contains many common required trigrams.
Changes
cardinalitycolumn to NGram postings, storing the row-count of each trigram posting list.regex_ngramwith skewed conjunction cases for cardinality-aware posting-list planning and allows scaling row count withLANCE_REGEX_NGRAM_TOTAL.Why
For a regex conjunction, every required trigram must be present. If one required trigram is absent, the candidate set is empty and there is no need to load/intersect other posting lists.
When all required trigrams are present, intersecting smaller posting lists first avoids cloning and intersecting large Roaring bitmaps early. This is the same selectivity principle used by inverted-index query planning: rare terms are more valuable filters than common terms.
Benchmark Results
Measured with the final
rust/lance/benches/regex_ngram.rsbenchmark data:HEAD^plus the benchmark-only patch is compared against this PR.Both runs use the same negative conjunction query:
Default 200k-row run:
10M-row scale run:
[783.43 us, 803.03 us, 829.14 us][417.02 us, 435.05 us, 454.90 us][10.734 ms, 10.779 ms, 10.843 ms][465.45 us, 471.39 us, 482.43 us]The biggest improvement is in negative conjunction cases where a regex contains many common required trigrams plus a missing required trigram. The new path can return an empty candidate set before loading large common posting lists.
Compatibility
tokens,cardinality,posting_listtokens,posting_listtoken_cardinalitiesisNone, and the index falls back safely.The old-format path checks the index file schema before choosing the projection. This avoids an intentional failed read on old-format postings and keeps compatibility covered in the NGram tests.
Testing
cargo fmt --allcargo test -p lance-index ngramcargo test -p lance --bench regex_ngramcargo bench -p lance --bench regex_ngram -- many_common_missing_trigramLANCE_REGEX_NGRAM_TOTAL=10000000 cargo bench -p lance --bench regex_ngram -- many_common_missing_trigramcargo clippy --all --tests --benches -- -D warnings