Skip to content

feat(scanner): ignore selected scalar indices - #9034

Merged
Xuanwo merged 13 commits into
lance-format:mainfrom
majin1102:codex/exclude-scalar-indices
Nov 1, 2026
Merged

Xuanwo merged 13 commits into
lance-format:mainfrom
majin1102:codex/exclude-scalar-indices

Conversation

@majin1102

@majin1102 majin1102 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

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, Python ignored_scalar_indices, and Java ignoredScalarIndices. Names are excluded before scalar filter parsers and index details are loaded.

Query semantics

  • The original expression filter is still evaluated. Explicit fragment and row selections continue to bound the scan; callers should pass their intended scope explicitly.
  • Existing fast_search behavior 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.
  • Unknown names do not fail the query or change its plan. A debug log lists names absent from the dataset's index metadata without opening index files for diagnostics.
  • Inverted index names also apply to expression filters such as 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 = false continues to disable scalar-index planning regardless of the ignored list.

Compatibility

  • LanceFragment.to_table preserves the released positional parameter order. ignored_scalar_indices is appended after the existing parameters.
  • DatasetIndexInternalExt retains its released callable methods. Ignored-name planning is implemented as crate-private Dataset helpers, with no new required trait methods for downstream implementers.

@github-actions github-actions Bot added A-python Python bindings A-java Java bindings + JNI enhancement New feature or request labels Sep 7, 2026
@majin1102 majin1102 changed the title feat(scanner): exclude named scalar indices feat(scanner): ignore selected scalar indices Sep 7, 2026
@majin1102
majin1102 marked this pull request as ready for review September 7, 2026 12:18
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-07T12:24:07.332032Z 9503cee Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Sep 7, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 7, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 7, 2026

@LuciferYang LuciferYang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@majin1102 majin1102 Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread rust/lance/src/index.rs Outdated
// 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Sep 29, 2026
Merge upstream main, preserve fast_search fallback semantics, document inverted-index filtering, log unmatched ignored names, and add effective regression coverage.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 29, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 29, 2026
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.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 30, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 30, 2026
Xuanwo pushed a commit that referenced this pull request Sep 30, 2026
## 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.
@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 30, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 8, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 8, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
…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
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 1, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 1, 2026
@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Nov 1, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 1, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Nov 1, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 1, 2026

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-java Java bindings + JNI A-python Python bindings enhancement New feature or request K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants