Skip to content

refactor(lsm): gate SSTable exclusion on every index a query relies on - #3780

Merged
xuanyu-z merged 2 commits into
mainfrom
feat/memwal-multi-index-lsm-coverage-pr
Aug 13, 2026
Merged

xuanyu-z merged 2 commits into
mainfrom
feat/memwal-multi-index-lsm-coverage-pr

Conversation

@xuanyu-z

@xuanyu-z xuanyu-z commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

exclusion_watermarks resolved a single index and capped SSTable exclusion at that index's catch-up watermark. It now takes every index the query relies on and retains to the lowest of them, and the resolver collects arms together rather than returning at the first match.

This is groundwork, not a fix for a reachable bug: reject_unsupported refuses hybrid search, so the vector and full-text arms are mutually exclusive and the list never holds more than one entry today. The generalisation is what the remaining work below plugs into.

Unchanged: a plain scan uses the compaction watermark alone, an index with no catch-up entry contributes no cap, and a caught-up index falls back to the compaction watermark. Taking a minimum over more indexes can only lower a watermark, so the failure direction is "read an SSTable unnecessarily", never "miss rows".

Tests

Three in lsm: the existing lagging-index test updated for the new signature; exclusion_watermark_takes_the_minimum_across_every_index_used (two indexes at 7 and 4 against compaction at 9 — each alone stops at its own watermark, together the lower governs, order-independent); and an_untracked_index_does_not_widen_a_lagging_sibling.

cargo test -p lancedb --lib — 45 lsm tests, 484 in the crate. cargo fmt --check clean.

Follow-ups

This crate pins lance to a released tag, so anything needing unreleased Lance symbols waits for a bump.

  1. Select legacy versus strict semantics from the feature bit. On a table with FLAG_MEM_WAL_INDEX_CATCHUP set, a missing entry must mean "not caught up" and retain the SSTables, instead of leaving the compaction watermark unchanged. Needs the bit from feat(mem-wal): record index catch-up positions and withdraw them on index change lance-format/lance#8263. This must land before any table is activated — otherwise the bit is set while queries still read permissively.
  2. Collect scalar and bitmap-family prefilter indexes. The genuinely multi-index query is a vector search with a scalar prefilter, and it is gated on the vector index alone today. Identifying the others needs the planner's chosen indexes, not the columns the filter names, so it needs a Lance-side helper.
  3. Verify a retained SSTable can actually answer. Both base and SSTable arms use fast_search; a source without a compatible index contributes nothing, so retention alone does not guarantee its rows are returned. Needs a flat-search fallback or an explicit error in Lance's LsmScanner.
  4. Planner-level integration tests. Current tests exercise the watermark arithmetic directly. End-to-end coverage over real queries — prefilter forms, legacy versus activated, missing index and missing shard entries — depends on 1–3.

@github-actions github-actions Bot added bug Something isn't working Rust Rust related issues labels Aug 5, 2026
@xuanyu-z xuanyu-z changed the title fix(lsm): gate SSTable exclusion on every index a query uses refactor(lsm): gate SSTable exclusion on every index a query relies on Aug 9, 2026
@xuanyu-z
xuanyu-z marked this pull request as ready for review August 9, 2026 06:48

@claude claude 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.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@lancedb-gatekeeper lancedb-gatekeeper 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.

⚠️ Gate recommendation: approve with a non-blocking risk.

The per-shard minimum is the right conservative rule, and the helper tests cover ordering and legacy missing-entry behavior without changing today’s supported zero/one-index paths.

This remains scaffolding: the only reachable multi-index shape, vector search with a scalar or bitmap prefilter, is still gated on the vector index alone, and there is no end-to-end divergent-catch-up test. Before activating strict catch-up semantics or relying on this for completeness, land planner-derived filter-index discovery plus an integration test that independently lags each used index; alternatively, conservatively gate on all maintained indexes until the planner can certify the selected set.

@Xuanwo Xuanwo added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Aug 10, 2026
The MemWAL LSM scanner resolved one index and capped SSTable exclusion at that
index's catch-up watermark. A query can rely on more than one: a hybrid search
reads both a vector and a full-text index, and either may lag the other. Gating
on whichever was resolved first dropped SSTables holding rows the other index
had not yet indexed, and that arm silently returned fewer rows.

exclusion_watermarks now takes every index the query relies on and retains to
the lowest of their watermarks, and the resolver collects the vector and
full-text arms together rather than returning at the first match. A plain scan
still uses the compaction watermark alone.

Both remaining behaviours are unchanged: an index with no catch-up entry
contributes no cap, and a caught-up index falls back to the compaction
watermark.

Two parts of the safe-retirement query behaviour are not here because they
depend on Lance changes this repository cannot yet see -- lancedb pins lance to
the v10.1.0-beta.2 tag:

- selecting legacy versus safe semantics from the manifest feature bit, so that
  on an activated table a *missing* coverage entry means "unknown" and retains
  SSTables rather than reading as "fully caught up";
- collecting scalar and bitmap-family indexes used as prefilters, which needs
  the filter's referenced columns and so must handle SQL, Substrait and
  Datafusion filter forms.

Both land once lance carries the feature bit and this crate is bumped.
The justification cited hybrid search, which `reject_unsupported` refuses in
the same file, so the multi-index path it described cannot occur. The list
never holds more than one entry today.

The case that is genuinely multi-index -- a vector search with a scalar or
bitmap prefilter -- is not collected, because identifying it needs the
planner's chosen indexes rather than the columns the filter names, and no
Lance API exposes them. Says so where the collecting happens.
@xuanyu-z
xuanyu-z force-pushed the feat/memwal-multi-index-lsm-coverage-pr branch from dc586ff to a47f57b Compare August 12, 2026 19:13

@hamersaw hamersaw 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.

Looks great, thanks for the fix!

@xuanyu-z
xuanyu-z merged commit 251f194 into main Aug 13, 2026
30 checks passed
@xuanyu-z
xuanyu-z deleted the feat/memwal-multi-index-lsm-coverage-pr branch August 13, 2026 17:23
xuanyu-z added a commit that referenced this pull request Aug 14, 2026
…#3911)

> Stacked on #3780. Blocked only on #3922 (`lance` → `v11.0.0-beta.6`),
so CI
> stays red until that lands.

## Missing coverage must mean "not known to be covered"

#3780 caps the SSTable exclusion watermark at an index's recorded
catch-up when
there is one, and silently ignores the case where there is none. On a
table that
requires catch-up, an absent entry means the index is *not* known to
hold the
compacted rows — and the LSM base arm reads base through the index
(`fast_search`, no brute-force tail), so dropping that SSTable loses
those rows
for that query.

```rust
Some(caught_up) => watermark = watermark.min(caught_up),
None if catchup_required => watermark = 0,   // retain everything
None => {}
```

`catchup_required` reads the manifest feature bit directly, and requires
both
words: a half-set manifest is treated as legacy, which is the
conservative side.
Without the bit the field is not maintained at all, so absence carries
no
information and behaviour is unchanged.

## Activation, as a table-level entry point

`Table::require_mem_wal_index_catchup()` performs the one-way switch,
separate
from `set_lsm_write_spec`: a table carrying the bit retains every
generation
until something records catch-up, so it has to follow the deployment of
whatever
repairs coverage, not the creation of the table.

This is a convenience, not the only path — a writer holding the dataset
calls
the equivalent on `DatasetMemWalExt`, which is what the WAL pod does.
Lance
enforces the preconditions either way: the MemWAL index must exist, and
the
table must not already carry `compacted_sstables` from before this
protocol,
since those numbers cannot be validated.

## Still correct after the Lance rework

lance-format/lance#8481 replaced the transmitted `IndexCatchupAdvance`
with a
position derived at commit time from the version a transaction read.
That
changed how a writer earns coverage; it did not change what a reader may
conclude from its absence. The rule here, and the field it reads, are
unchanged.

## Tests

Existing `exclusion_watermarks` unit tests carry the new argument.
Coverage
against a real dataset follows once #3922 lands and this can build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. Rust Rust related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants