Repository navigation
feat(mem_wal): answer memtable filters with Lance's scalar expression pass - #9804
Merged
jackye1995 merged 9 commits intoOct 10, 2026
Merged
Conversation
xuanyu-z
force-pushed
the
memwal-filter-expression-pass
branch
from
October 8, 2026 21:10
5e171fd to
563b528
Compare
xuanyu-z
force-pushed
the
memwal-filter-expression-pass
branch
10 times, most recently
from
October 9, 2026 19:21
d0fff70 to
df1a6e2
Compare
xuanyu-z
marked this pull request as ready for review
October 9, 2026 19:22
xuanyu-z
force-pushed
the
memwal-filter-expression-pass
branch
from
October 9, 2026 20:02
df1a6e2 to
807829e
Compare
xuanyu-z
force-pushed
the
memwal-filter-expression-pass
branch
from
October 9, 2026 20:17
807829e to
9bda73f
Compare
xuanyu-z
force-pushed
the
memwal-filter-expression-pass
branch
from
October 9, 2026 22:34
9bda73f to
8915c06
Compare
jackye1995
pushed a commit
that referenced
this pull request
Oct 9, 2026
…table index plugins (#9805) Independent of #9804: based on `main`, and either can merge first. ## Why A memtable index plugin can take no settings from the writer beyond HNSW's own, and every scalar index it hands to the flush is built with the index type's default parameters. A plugin whose in-memory structure or flushed index has tunable settings has no way to receive them. ## What changes - **Writer settings reach any plugin.** `ShardWriterConfig::index_overrides` (`with_index_override`) carries each index's settings, by index name, as the type its plugin reads through `ResolveContext::overrides`. The HNSW settings (`hnsw_params`) feed the same channel; naming one index in both is an error. Each writer passes its own: unlike `hnsw_params`, these settings are not recorded as writer defaults. - **A plugin that reads settings checks their type.** Settings of a type the plugin does not read stop the writer from opening, instead of falling back to defaults. Settings for an index whose plugin reads none are ignored, as before, and logged. - **A scalar flush uses the plugin's parameters.** `MemIndexPlugin::flush_params(spec)` gives the parameters for `BuildFromGeneration` and `TrainingData` builds; by default these are the index type's default parameters, so the built-in kinds build as before. The writer calls it when it opens, so a plugin rejecting its parameters stops the writer from opening rather than failing a flush. - **The plugin contract is written down** on `resolve` and `flush_params`: read settings through `ResolveContext::overrides`, keep them in the params `resolve` returns so they reach both the in-memory index and the flush, and so a changed setting is a different index under `MemIndexSpec::same_index`. No behaviour of the built-in kinds changes. ## Breaking changes - `ShardWriterConfig` gains a public `index_overrides` field. - `ResolveContext::overrides` returns `Result<Option<&P>>`; its settings are no longer a public field, and the context is built only by Lance. ## Testing - Non-default HNSW settings given through `index_overrides` are the ones the index is built with. - Settings of the wrong type stop the writer from opening; settings for a kind that reads none are ignored and the index is maintained; settings named in both channels stop the writer from opening. - A B-tree flushed with a non-default zone size records that zone size on disk, both when the index hands over its rows and when the flush reads the generation. - A plugin rejecting its flush parameters fails validation. - `cargo nextest run -p lance` passes (5,308 tests); `cargo clippy -p lance --all-targets -- -D warnings`, `cargo doc -p lance` with `-D warnings` and `cargo fmt --all -- --check` are clean.
…ep the catalog crate-private
xuanyu-z
force-pushed
the
memwal-filter-expression-pass
branch
from
October 9, 2026 23:08
8c4f5b8 to
8aca5d9
Compare
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The index_details rename is consistent across spec construction, query parsing, and index identity checks. Indexed filtering still matches full scans after the rebase, including visibility, fallback, projection, and Blob rechecks. No remaining blocker found.
Please mark this PR with the breaking-change label.
jackye1995
approved these changes
Oct 10, 2026
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.
Why
The memtable has its own predicate vocabulary and a hand-written match over
Exprthat recognises=,<,>=andINon one column. Any other filter reads every memtable row, so<=,>,IS NULL,LIKE 'prefix%'andANDacross two indexed columns never use an index.How a filter reaches an index
flowchart TB subgraph before["Before: a match written for the memtable"] f1["filter Expr"] --> m1{"one column, compared by<br/>equals, less than, at least,<br/>IN, or an OR of equals?"} m1 -- yes --> b1["that column's B-tree<br/>(BTreeIndexExec)"] m1 -- no --> s1["read every memtable row<br/>and apply the filter"] end subgraph after["After: the pass the base table's scan uses"] f2["filter Expr"] --> p2["apply_scalar_indices<br/>with each index's ScalarQueryParser<br/>(MemIndexPlugin::query_parser)"] p2 --> t2["tree of index searches<br/>AND / OR across indexes<br/>+ leftover expression"] t2 --> e2["ScalarMemIndexExec: evaluate the tree,<br/>clamp to visible rows"] e2 --> r2{"answered exactly?"} r2 -- yes --> o2["rows"] r2 -- no --> c2["re-check the whole filter<br/>on the narrowed rows"] --> o2 p2 -- "nothing claimed, or NOT" --> s2["read every memtable row<br/>and apply the filter"] e2 -- "an index over its match budget declines" --> s2 endA memtable index then claims exactly the expressions its on-disk counterpart claims, and a single-column plugin kind is reachable from a filter by giving its parser, with no change to the memtable's planner.
What changes
Filters go through
apply_scalar_indices, the pass the base table's scan uses, with a provider built from the memtable's indexes. A plugin supplies the query parser its on-disk counterpart uses (MemIndexPlugin::query_parser), so both claim the same expressions. The result is a tree of per-index queries and a leftover expression. The tree goes throughScalarIndexExpr::optimize, as on the base table, so bounds on one column split by another conjunct are searched as one range.ScalarMemIndexExecevaluates the tree and applies the whole filter to the rows it narrowed to unless the indexes answered all of it exactly.ScalarPredicateandBTreeIndexExecare removed. A list column compared with a list literal is cast because of nested field ids; the split looks through a cast that changes no value.A broad answer is not listed. Only a batch's candidate rows are read, and the filter is re-checked on those rows alone. The scan offers an index a match budget (
SearchContext::match_budget: a sixteenth of the visible rows, never under 4,096); an index that would list more may decline, and every visible row is read with the filter. The built-in B-tree honours it. A failed search is an error, not a read of every row. On 100,000 rows with B-trees on an integer and a string column (mainreads every row for the shapes marked *):mainid = 54321id >= 10000 AND id < 11000(1%)id >= 10000 AND id < 20000(10%)id >= 0 AND id < 50000(50%)id >= 0(every row)name LIKE 'k05%'(10%)The memtable's own key index answers filters too. With no maintained index on a single-column key, the B-tree the memtable keeps for its key is in the catalog, under a name no base-table index can carry, so
id = 4,id IN (...)and key ranges still use an index, as before.B-tree ranges honour each bound. An inclusive upper bound adds its key's rows and an exclusive lower bound removes them, the latter by a binary search over that key's sorted rows; a range whose bounds cross matches nothing.
Breaking changes
ScalarPredicateandBTreeIndexExecare removed;ScalarMemIndexExecanswers a filter from any filter index.SearchContextgains a publicmatch_budgetfield;SearchContext::newleaves it unset.MemIndexSpecgains a publicindex_detailsfield (the base-table index's details message), so building one with a struct literal must set it.Known limitations
NOTis not evaluated from indexes: complementing a result needs each index's null rows, which indexes do not report yet. A filter with aNOT-shaped part (<>,NOT IN,IS NOT NULL) reads every row.Testing
ANDandOR, and requires the index route to return exactly the rows a full read returns; with every column indexed, a filter on each type is checked to take the index route.AND/ORacross two indexes compose; an unindexed conjunct comes back as the leftover;NOTis scanned; a list comparison is claimed through the cast.IS NULLincluded; split bounds on one column are merged so neither declines alone; a search with no filter to fall back on is never declined; exclusive and inverted ranges on each backend, over a key held by thousands of rows; a declined answer reads exactly the filter's rows and row ids; candidates that fill a batch and candidates that are a few of its rows are both re-checked and keep their own row ids.cargo nextest run -p lancepasses (5,337 tests);cargo clippy -p lance --tests --benches -- -D warnings,cargo doc -p lance --no-depswith-D warningsandcargo fmt --all -- --checkare clean.