perf(fts): push prefilter through scalar index on flat FTS#7283
Open
LuQQiu wants to merge 4 commits into
Open
Conversation
Flat FTS (no inverted index on the text column) used `scan_fragments` + a manual `LanceFilterExec` to apply the prefilter, bypassing any scalar index on the filter column. Route the scan through `filtered_read` instead, matching the brute-force KNN path, so the pushable part of the prefilter is evaluated inside `FilteredReadExec` (using a scalar index when one exists) and only the unpushable `refine_expr` is reapplied on top. Requires `prefilter(true)` on the scanner — the postfilter branch still sends an empty filter plan down and is unaffected. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
Author
|
Duplicate; reopening against lancedb/lance via API. |
The flat-FTS scan now goes through `FilteredReadExec`, so the golden plans in `test_plans` need to reflect both shapes: - No prefilter: legacy emits `LanceScan` with `ordered=true` (vs. the old hardcoded `ordered=false`); v2 emits `LanceRead` with empty filters. Functionally equivalent — output still feeds an outer SortExec by score. - With prefilter on an indexed column: the BTree now pushes into the unindexed-fragment scan. Legacy uses the `MaterializeIndex` shape, v2 uses `LanceRead` with `full_filter` set — same pushdown the indexed `MatchQuery` side already had. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…redRead The flat-FTS path now reads through `FilteredReadExec` (`LanceRead`), so the unindexed-fragment branch shows `LanceRead` instead of `LanceScan` and the BTree on `id` pushes into the flat scan too. Update the assertion to reflect the new pushdown. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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
scan_fragments+ a manualLanceFilterExecto apply the prefilter, bypassing any scalar index on the filter column.filtered_readinstead — same pattern as the brute-force KNN path atscanner.rs:3839-3848— so the pushable part of the prefilter is evaluated insideFilteredReadExec(using a scalar index when one exists) and only the unpushablerefine_expris reapplied on top.prefilter(true)on the scanner. The postfilter branch passes an emptyExprFilterPlan::default()down the FTS path and is unaffected.Plan shape
Before (with
WHERE id = 1and a BTree onid, no FTS index ontext):After:
Test plan
test_fts_without_index_uses_scalar_index_for_prefilterindataset_index.rs: BTree onid, no FTS index, flat FTS +id = 1prefilter with.prefilter(true). Asserts viaanalyze_planthatLanceReadshowsfull_filter=id = Int32(1), noLanceScan:in the plan, and the result set is correct (2 rows).cargo fmt --allcargo clippy --all --tests --benches -- -D warnings