Repository navigation
feat(scanner): ignore selected scalar indices - #9034
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9503ceeb27
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
LuciferYang
left a comment
There was a problem hiding this comment.
The placement is good. Only one production site reads ScalarIndexInfo (the expression-filter branch of create_plan; the other three scalar_index_info calls in filtered_read.rs are inside #[cfg(test)] mod tests), so there is no path left unwired, and scalar_index_info_ignoring rebuilds from load_indices() on every call without writing any session cache, so a filtered result cannot leak to another caller.
Four comments inline, two MEDIUM and two LOW, none blocking. The one I would like settled before merge is the fast_search interaction: putting a column's only scalar index in the ignore list removes the index query, which also removes the only_indexed_fragments restriction, so the same fast_search query comes back with a different row set. The result is a superset rather than wrong rows, and use_scalar_index(false) already behaves this way, but the docs enumerate the other cases the option does not control and omit this one.
The second MEDIUM is observability: an unmatched name is a no-op that nothing reports, and the cross-process use case this option exists for is exactly where names drift. One debug log covers it.
Two things I checked that are fine: the Java and Python plumbing has no silent drop (env.get_strings_opt matches Optional<List<String>>, both native declarations agree with the Rust parameter positions, the Builder copy constructor carries the field, and the pyo3 signatures line up with to_scanner's positional call), and the ignore list correctly stays a planning-time input rather than something that has to travel with a serialized plan, since index selection is already baked into the physical plan.
| /// # Ok(()) | ||
| /// # } | ||
| /// ``` | ||
| pub fn with_ignored_scalar_indices<I, S>(&mut self, index_names: I) -> &mut Self |
There was a problem hiding this comment.
[MEDIUM · behavior compatibility] fast_search only sets only_indexed_fragments when filter_plan.has_index_query() holds (scanner.rs:3543). Once the only scalar index on a column is in the ignore list, create_filter_plan produces no index query, that branch is skipped, and unindexed fragments get scanned too, so the same fast_search query returns a different row set with the ignore list than without it. It is a superset, since the filter still refines, so no wrong rows.
The docs here enumerate what the option does not control (vector index segments, explicit full-text search, and being ignored under use_scalar_index=false) but not fast_search. use_scalar_index(false) behaves the same way, so the interaction is not new; a selective switch just makes it easier to hit.
A sentence in the docs is enough. If you do change the behavior, do not keep only_indexed_fragments unconditionally: existing fast_search queries whose filter has no usable index would start dropping unindexed fragments.
There was a problem hiding this comment.
Addressed in 6489580. We preserved the existing behavior: scalar fast_search skips unindexed fragments only when the remaining filter plan uses an index. If ignoring indices removes every index query, the scan falls back to all selected fragments and may return more matching rows.
Updated the Rust, Python, and Java docs and the PR description. Added regression coverage for a remaining usable index, fully ignored indices, and preservation of an explicit row selection during fallback. Callers that need to preserve a driver-defined scan scope should pass that selection explicitly.
| // so the optimizer treats coverage as unknown. | ||
| let mut fragment_bitmaps: HashMap<(String, String), Option<RoaringBitmap>> = HashMap::new(); | ||
| for index in indices.iter().filter(|idx| { | ||
| if ignored_index_names.contains(&idx.name) { |
There was a problem hiding this comment.
[MEDIUM · robustness] The filter is ignored_index_names.contains(&idx.name), so a misspelled name or a renamed index makes the option do nothing, and nothing reports the miss: explain_plan still prints @a_zonemap(ZoneMap), exactly as it would without the ignore list, and no log says which names matched nothing.
The use case this option exists for passes names across processes (the driver uses the ZoneMap, the executor skips it), which is exactly where names drift. The only symptom is the executor loading and probing the index for nothing while still returning the right rows, so nobody finds out.
A difference after load_indices() and one debug log for the names that matched nothing is enough, or have explain_plan(verbose) list the ignored names.
There was a problem hiding this comment.
Addressed in 6489580. Unknown names remain non-fatal, and a debug log now lists ignored names that are absent from the dataset’s index metadata. This uses the metadata already returned by load_indices() and does not open additional index files.
Tests cover unknown names both alone and alongside a valid ignored name, verifying that valid exclusions still apply and unknown names do not change query behavior.
| .build(); | ||
| try (AsyncScanner scanner = AsyncScanner.create(dataset, options, allocator); | ||
| ArrowReader reader = scanner.scanBatchesAsync().get(10, TimeUnit.SECONDS)) { | ||
| assertEquals(20, countRows(reader)); |
There was a problem hiding this comment.
[LOW · tests] The test creates id_btree_index, puts it in the ignore list, and then asserts only that the row count is 20, which it is either way, so the test passes whether or not the ignore list is wired up. The blocking sibling (ScannerTest.java:1294) distinguishes with getIndexComparisons() == 0, and the Rust test asserts the plan no longer contains the index; both are effective.
AsyncScanner has no getStats, so the blocking assertion cannot be copied, and re-asserting getIgnoredScalarIndices() would add nothing because ScannerTest already does it. Exercising the async path for real needs a stats accessor on AsyncScanner; without one, this test only covers what it shares with the blocking path through build_scanner_with_options.
There was a problem hiding this comment.
Addressed in 6489580 by extending the existing multi-fragment async test. With fast_search, the indexed query returns 5 rows; ignoring that index causes fallback and returns 10 rows. If the ignore list is dropped anywhere in the async JNI path, the new assertion fails.
Removed the redundant single-fragment test. No new statistics API was needed. The Scanner/AsyncScanner tests and JNI tests pass.
| * @param indexNames logical scalar index names to ignore. | ||
| * @return Builder instance for method chaining. | ||
| */ | ||
| public Builder ignoredScalarIndices(List<String> indexNames) { |
There was a problem hiding this comment.
[LOW · docs] The early return at index.rs:3449 sits ahead of the FTS branch in the same closure, and ScalarIndexInfo does carry inverted indices (inverted.rs:456's new_query_parser registers the FtsQueryParser that handles contains_tokens). So putting an inverted index name in the ignore list also turns off contains_tokens pushdown, falling back to the flat UDF.
All three doc copies say only that the option does not control explicit full-text search. That is true, since explicit FTS never goes through ScalarIndexInfo, but it reads as though inverted indices are unaffected. One sentence saying inverted index names are honored too would cover it.
There was a problem hiding this comment.
Addressed in 6489580. The Rust, Python, and Java docs now explicitly state that inverted index names are honored for expression filters such as contains_tokens, while explicit full-text search queries remain unaffected.
Extended the existing contains_tokens test with an appended fragment and an ignored inverted index. It verifies that the plan no longer contains ScalarIndexQuery and that the returned values match the expected filtered results.
Merge upstream main, preserve fast_search fallback semantics, document inverted-index filtering, log unmatched ignored names, and add effective regression coverage.
Preserve ignored_scalar_indices alongside the new substrait_filter argument. Cover Arrow expression filters with and without ignored indices, and complete the upstream restore-conflict test initializer so Rust test targets compile.
## Problem and context An update can fail when a fragment stores its row lineage in data-file columns: ```text cannot commit fragment ...: it marks row lineage field -3 as spilled but none of its data files carries it ``` Row lineage records each row's stable ID, creation version, and last-update version. To keep large per-row sequences out of the manifest, Lance's opt-in spilled-lineage feature can store them as hidden columns in a fragment's data files. Their reserved field IDs (`-3`, `-4`, and `-5`) are absent from the user schema. A fragment's metadata marks which sequences use this storage, and its file list must retain the files carrying those columns. The regression comes from the interaction between two changes: - #9339 added spilling for updates and preserved lineage files across schema changes in the Project and DataReplacement paths. - Later, #9219 added file pruning to the Update manifest path. This pruning is necessary when an update was prepared before a concurrent Project removed a user column: committing the older update must not restore files containing only removed columns. It filters both updated fragments and newly written fragments against the current user schema. The new Update pruning checked only user-schema field IDs. Consequently, it also discarded files containing only hidden lineage columns. This check runs during Update manifest construction even without a concurrent schema change, so an ordinary update can trigger the failure. For example, a fragment can have these files: ```text fragment |-- data.lance [live user field 0] |-- old-column.lance [removed user field 1] `-- lineage.lance [hidden row ID field -3] ``` Pruning should remove `old-column.lance` and retain the other two. Before this fix it also removed `lineage.lance` from the fragment's file list, while the metadata still said row IDs were stored in a column. Commit-time validation then rejected the inconsistent manifest. The observed failure is a rejected commit; this pruning does not physically delete the file. This reproduced in five existing spill tests and caused the Rust CI failures on Linux x86_64, Linux ARM, Windows, and macOS observed on #9034. The failure is in shared Update manifest construction and does not depend on that PR's ignored-index option. ## Fix In both Update pruning locations, retain a file when it contains either a live user field or a spilled lineage field required by that fragment's metadata. This follows the existing Project rule, preserves all three lineage kinds, and continues to remove files containing only projected-out user fields. Carrier validation remains in place. No public API or file format changes are needed. Extend the existing Update manifest regression across the unspecified update mode, RewriteRows, and RewriteColumns, each with and without spilled lineage (six cases). The v2 fixtures use separate files for row IDs, creation versions, and last-update versions, and assert the exact retained file lists for both updated and new fragments. The second changed file only completes the restore/config conflict test's `TransactionRebase` initializer. Its six missing fields otherwise prevent Rust test targets from compiling on the base revision; this is a separate test-build fix. ## Validation - Before the fix: the spill suite had 31 passes and 5 failures with the missing-carrier error. - `cargo test -p lance-table --locked`: 580 unit tests and 3 doc tests passed. - `cargo test -p lance --lib --locked`: 4488 passed, 0 failed, 3 existing ignored tests; all five previously failing spill cases passed. - The six Update manifest regression cases passed again after the test-only clippy cleanup. - `cargo fmt --all` and `cargo clippy --all --tests --benches -- -D warnings` passed.
…uanwo/pr-9034-merge-20261101 # Conflicts: # python/python/lance/dataset.py # rust/lance/src/dataset/scanner.rs # rust/lance/src/dataset/tests/dataset_index.rs
…uanwo/pr-9034-merge-20261101
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The main-branch merge leaves selective exclusion at scalar-index discovery, before FTS posting-cache work. Original filters, explicit row/fragment scope, other eligible indices, and the documented scalar fast_search fallback remain intact. Inverted-filter fallback and vector/explicit FTS behavior are preserved. The Rust trait entry points, Python positional calls, and Java/JNI wiring are unchanged.
Xuanwo
left a comment
There was a problem hiding this comment.
Approved after full applicable CI and Gatekeeper review on the final head. The released Python positional API and Rust trait signatures remain compatible while ignored scalar-index selection preserves filters, explicit scope, remaining indices, and fast_search fallback semantics.
Summary
External planners can use a scalar index on the driver and pass an explicit row or fragment selection to Lance workers. Workers can now ignore that index by logical name, avoiding duplicate index work while keeping other scalar indices available.
The option is exposed as Rust
with_ignored_scalar_indices, Pythonignored_scalar_indices, and JavaignoredScalarIndices. Names are excluded before scalar filter parsers and index details are loaded.Query semantics
fast_searchbehavior is preserved: scalar filters skip unindexed fragments only while the remaining filter plan uses an index. If ignoring indices removes every index query, the scan falls back to all selected fragments and may return more matching rows. With a usable remaining index, indexed-fragment pruning still applies.contains_tokens, disabling that index's pushdown and falling back to function evaluation. Vector index segment selection and explicit full-text search queries are unaffected.use_scalar_index = falsecontinues to disable scalar-index planning regardless of the ignored list.Compatibility
LanceFragment.to_tablepreserves the released positional parameter order.ignored_scalar_indicesis appended after the existing parameters.DatasetIndexInternalExtretains its released callable methods. Ignored-name planning is implemented as crate-privateDatasethelpers, with no new required trait methods for downstream implementers.