perf(index): use NGram posting cardinalities for regex conjunction search#7390
Draft
everySympathy wants to merge 1 commit into
Draft
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! |
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.ngram_load_compatbenchmark for old two-column postings load performance.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
Regex Query Benchmarks
commonmarkerabcdefghijklmnopqrstuvwx.*missingmarkercommoncommon.*missingmarkerdensecommonprefix.*longrareanchor.*densecommonsuffixcommoncommon.*raremarkercommonmarkerabcdefghijklmnopqrstuvwx.*missingmarkerThe 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.
Old Index Compatibility Benchmark
A new benchmark was added for loading older two-column NGram postings without cardinality metadata:
old_two_column_postings(50000)[1.9769 ms, 2.0122 ms, 2.0450 ms][1.9578 ms, 1.9714 ms, 1.9852 ms]This shows the schema-based compatibility path does not regress old-format index loading.
Compatibility
tokens,cardinality,posting_listtokens,posting_listtoken_cardinalitiesisNone, and the index falls back safely.The old-format path now checks the index file schema before choosing the projection, instead of attempting a read that may fail.
Testing
cargo fmt --allcargo test -p lance-index ngramcargo test -p lance-index --bench ngram_load_compatcargo bench -p lance-index --bench ngram_load_compat -- old_two_column_postingscargo clippy --all --tests --benches -- -D warnings