Skip to content

feat(index): incorporate data overlays when merging scalar index segments - #11273

Draft
ddupg wants to merge 3 commits into
lance-format:mainfrom
ddupg:fix/fts-merge-overlay
Draft

ddupg wants to merge 3 commits into
lance-format:mainfrom
ddupg:fix/fts-merge-overlay

Conversation

@ddupg

@ddupg ddupg commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #11272. This addresses the full-text search (FTS) part of #11180.

Summary

A scalar index merge can combine segments built before and after the same data overlay. This draft refreshes each source against the snapshot used for the merge. It uses the source’s fragment coverage, indexed fields and build version to decide which entries need replacing. Once the indexed values and row references are current, the output segment can record the merge snapshot’s dataset_version.

  • Ordinary optimize_indices, explicit segment merges, and distributed optimize share the overlay refresh logic.
  • Row-oriented indices discard stale entries and train replacements from current values. FTS retains already-indexed hits under fast_search and indexes updated documents from older inputs. ZoneMap and BloomFilter can rebuild summaries for affected fragments.
  • The merged segment can serve refreshed rows without a query-time overlay recheck. Advancing its build version also allows later cleanup to trim old compaction mappings once no index needs them.

Validation

  • cargo fmt --all and git diff --check passed.
  • Ten targeted tests passed in the preceding verification of this change, including ZoneMap physical merges with and without stable row IDs. The whole-fragment stable-ID translation test and two FTS merge regressions passed locally. The BloomFilter version assertion is covered by the Linux CI rerun. Local workspace Clippy on macOS arm64 stops on existing unreachable expressions in lance-encoding/src/encodings/physical/byte_stream_split.rs (lines 358 and 393).

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer enhancement New feature or request labels Nov 19, 2026
@ddupg
ddupg force-pushed the fix/fts-merge-overlay branch from 81ad0f9 to be95d12 Compare November 19, 2026 14:21
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
9600 1 9599 0
View the top 1 failed test(s) by shortest run time
lance::index::vector::ivf::v2::tests::test_distributed_vector_build_commits_multiple_segments_and_preserves_query_results::case_2_ivf_pq
Stack Traces | 1.24s run time
thread 'index::vector::ivf::v2::tests::test_distributed_vector_build_commits_multiple_segments_and_preserves_query_results::case_2_ivf_pq' (87048) panicked at .../ivf/v2/tests.rs:2910:9:
assertion `left == right` failed: single vs segmented distributed index returned different Top-K row ids
  left: [[0, 4, 37, 4294967335, 4294967386, 8589934649, 66, 4294967301, 12884902006, 26], [1, 123, 8589934691, 12884901897, 48, 12884901913, 12884901992, 4294967377, 4294967325, 8589934705], [2, 4294967382, 12884901923, 8589934707, 4294967305, 4294967309, 8589934665, 8589934697, 12884901929, 8589934677], [3, 49, 27, 8589934644, 12884901934, 8589934682, 12884901924, 4294967323, 12884901908, 12884901968], [4, 8589934649, 66, 4294967351, 93, 4294967335, 99, 4294967382, 15, 4294967311], [5, 8589934687, 32, 12884901980, 12884901913, 12884901897, 48, 4294967368, 8589934691, 31], [6, 12884901962, 111, 41, 4294967323, 4294967332, 115, 75, 4294967359, 12884901968], [7, 4294967393, 12884901976, 8589934677, 12884901913, 12884901967, 12884901925, 12884901972, 48, 8589934612], [8, 8589934686, 45, 8589934612, 32, 25, 8589934624, 8589934651, 12884901913, 4294967325], [9, 8589934660, 8589934627, 4294967383, 12884901970, 90, 8589934717, 12884901984, 4294967323, 12884901902]]
 right: [[0, 4, 37, 4294967335, 4294967386, 8589934649, 66, 4294967301, 12884902006, 26], [1, 123, 8589934691, 12884901897, 48, 12884901913, 12884901992, 4294967377, 4294967325, 8589934705], [2, 4294967382, 12884901923, 8589934707, 4294967305, 4294967309, 8589934665, 8589934697, 12884901929, 8589934677], [3, 49, 27, 8589934644, 12884901934, 8589934682, 12884901924, 4294967323, 12884901908, 12884901968], [4, 8589934649, 66, 4294967351, 93, 4294967335, 99, 4294967382, 15, 4294967311], [5, 8589934687, 32, 12884901980, 12884901913, 12884901897, 48, 4294967368, 8589934691, 31], [6, 12884901962, 111, 41, 4294967323, 4294967332, 115, 75, 4294967359, 12884901968], [7, 4294967393, 12884901976, 8589934677, 12884901913, 12884901967, 12884901925, 12884901972, 48, 8589934612], [8, 8589934686, 45, 8589934612, 32, 25, 8589934624, 8589934651, 12884901913, 4294967325], [9, 8589934660, 8589934627, 4294967383, 12884901970, 90, 8589934717, 12884901984, 4294967323, 4294967315]]
stack backtrace:
   0: __rustc::rust_begin_unwind
             at .../std/src/panicking.rs:679:5
   1: core::panicking::panic_fmt
             at .../core/src/panicking.rs:80:14
   2: core::panicking::assert_failed_inner
             at .../core/src/panicking.rs:434:23
   3: core::panicking::assert_failed::<alloc::vec::Vec<alloc::vec::Vec<u64>>, alloc::vec::Vec<alloc::vec::Vec<u64>>>
             at .../core/src/panicking.rs:394:5
   4: {async_fn#0}
             at ..../ivf/v2/tests.rs:2910:9
   5: {async_block#0}
             at ..../ivf/v2/tests.rs:2734:1
   6: poll<&mut dyn core::future::future::Future<Output=()>>
             at .../src/future/future.rs:133:9
   7: {closure#0}<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:830:70
   8: with_budget<core::task::poll::Poll<()>, tokio::runtime::scheduler::current_thread::{impl#9}::block_on::{closure#0}::{closure#0}::{closure_env#0}<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../task/coop/mod.rs:167:5
   9: budget<core::task::poll::Poll<()>, tokio::runtime::scheduler::current_thread::{impl#9}::block_on::{closure#0}::{closure#0}::{closure_env#0}<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../task/coop/mod.rs:133:5
  10: {closure#0}<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:830:25
  11: <tokio::runtime::scheduler::current_thread::Context>::enter::<core::task::poll::Poll<()>, <tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}::{closure#0}>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:486:19
  12: <tokio::runtime::scheduler::current_thread::CoreGuard>::block_on::<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:829:44
  13: <tokio::runtime::scheduler::current_thread::CoreGuard>::enter::<<tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, core::option::Option<()>>::{closure#0}
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:906:68
  14: <tokio::runtime::context::scoped::Scoped<tokio::runtime::scheduler::Context>>::set::<<tokio::runtime::scheduler::current_thread::CoreGuard>::enter<<tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, core::option::Option<()>>::{closure#0}, (alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core>, core::option::Option<()>)>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../runtime/context/scoped.rs:40:9
  15: tokio::runtime::context::set_scheduler::<(alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core>, core::option::Option<()>), <tokio::runtime::scheduler::current_thread::CoreGuard>::enter<<tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, core::option::Option<()>>::{closure#0}>::{closure#0}
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../src/runtime/context.rs:186:38
  16: try_with<tokio::runtime::context::Context, tokio::runtime::context::set_scheduler::{closure_env#0}<(alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core, alloc::alloc::Global>, core::option::Option<()>), tokio::runtime::scheduler::current_thread::{impl#9}::enter::{closure_env#0}<tokio::runtime::scheduler::current_thread::{impl#9}::block_on::{closure_env#0}<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>, core::option::Option<()>>>, (alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core, alloc::alloc::Global>, core::option::Option<()>)>
             at .../src/thread/local.rs:463:12
  17: <std::thread::local::LocalKey<tokio::runtime::context::Context>>::with::<tokio::runtime::context::set_scheduler<(alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core>, core::option::Option<()>), <tokio::runtime::scheduler::current_thread::CoreGuard>::enter<<tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, core::option::Option<()>>::{closure#0}>::{closure#0}, (alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core>, core::option::Option<()>)>
             at .../src/thread/local.rs:427:20
  18: tokio::runtime::context::set_scheduler::<(alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core>, core::option::Option<()>), <tokio::runtime::scheduler::current_thread::CoreGuard>::enter<<tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, core::option::Option<()>>::{closure#0}>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../src/runtime/context.rs:186:17
  19: <tokio::runtime::scheduler::current_thread::CoreGuard>::enter::<<tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, core::option::Option<()>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:906:27
  20: <tokio::runtime::scheduler::current_thread::CoreGuard>::block_on::<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:819:24
  21: {closure#0}<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:216:33
  22: tokio::runtime::context::runtime::enter_runtime::<<tokio::runtime::scheduler::current_thread::CurrentThread>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, ()>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../runtime/context/runtime.rs:65:16
  23: block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:204:9
  24: <tokio::runtime::runtime::Runtime>::block_on_inner::<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../src/runtime/runtime.rs:379:52
  25: block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../src/runtime/runtime.rs:348:18
  26: case_2_ivf_pq
             at ..../ivf/v2/tests.rs:2734:1
  27: lance::index::vector::ivf::v2::tests::test_distributed_vector_build_commits_multiple_segments_and_preserves_query_results::case_2_ivf_pq::{closure#0}
             at ..../ivf/v2/tests.rs:2734:10
  28: <lance::index::vector::ivf::v2::tests::test_distributed_vector_build_commits_multiple_segments_and_preserves_query_results::case_2_ivf_pq::{closure#0} as core::ops::function::FnOnce<()>>::call_once
             at .../src/ops/function.rs:250:5
  29: <fn() -> core::result::Result<(), alloc::string::String> as core::ops::function::FnOnce<()>>::call_once
             at .../src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@wombatu-kun

Copy link
Copy Markdown
Contributor

It looks like our work crossed in flight: #11260 and #11261 also address #11180, covering vector and FTS merges by retaining per-source overlay freshness. Your PR takes the other approach discussed in #10884: refreshing stale rows against the merge snapshot. It also goes beyond #11180 by bringing the other scalar indices up to date.

There is direct overlap in the FTS and shared merge lifecycle code, so I would like to coordinate rather than have us maintain competing FTS fixes. One possible split would be for this PR to own the scalar/FTS refresh, while I narrow #11260 and #11261 to the vector case. #11180 could then remain open until both the vector and FTS parts land.

What do you think? We can move the design discussion to #11180 so that everyone involved has the full context.

@ddupg
ddupg force-pushed the fix/fts-merge-overlay branch from 8683af9 to e0c153a Compare November 24, 2026 01:33
Xuanwo added a commit that referenced this pull request Nov 24, 2026
## Problem

Every scalar index merge repeated the same field and declaration
validation, row-domain guard, per-segment filters, destination store
allocation, source opening/downcast, and `IndexMetadata` assembly.
Bitmap also depended on btree for its empty new-data stream, and
append's merge dispatch rebuilt the same filters per arm.

## Change

Add `scalar/segment_merge.rs` to own the shared merge inputs and output:

- empty groups, keyed field/path and same-declaration checks
- per-type stable-row-id legacy guard, preserving
Bitmap/BTree/LabelList/MinHash bottom-level mixed-domain errors;
RTree/NGram keep the shared-domain guard
- per-segment filters and coverage unions
- typed source opening/downcast
- UUID/store allocation and one metadata constructor
- the empty value/address stream used by pure consolidation

All scalar merge modules now use it; Bitmap no longer reaches into
btree. `append.rs` constructs filters once for the simple merge
primitives. MinHash keeps its historical admission rule: non-stable
tables can merge disjoint v0 and v1 segments into v1, while stable
tables still reject legacy input.

No public API, persisted format, or Python wrapper changes. #11273,
#11231 and #11280 are complementary and not dependencies; their
behaviors are not pulled in here. Overlap is mechanical in the same
scalar modules and append dispatch. Current main's #11290 only changes
tagged FRI retention bookkeeping and #11391 changes commit
configuration; neither changes a caller contract used by this change.

## Validation

- `cargo fmt --all -- --check`: pass
- `cargo clippy --all --tests --benches --profile ci -j 4 -- -D
warnings`: pass (only existing lance-linalg build-script notices)
- Runtime on head `d23cbafd5`, one test executable, 49 unique tests:
- scalar MinHash module: 16 passed, including mixed v0-layout/v1
disjoint merge, commit, reopen and `fast_search` for both stable and
non-stable datasets, plus the historical-layout legacy regression
  - `index::tests::merge`: 8 passed
- append/optimize: BTree 9, Bitmap 7, NGram 1, BloomFilter 4, FTS 3,
scalar stale-row 1

No released MinHash v0 fixture exists; the v0 layout is reconstructed
from a current segment (`_rowid`, version 0) by the test helper. The
test exercises real merge, commit, reopen and search rather than mocked
metadata.

Remaining coverage: the full workspace test matrix and a Python wheel
were not run. The Python wrapper is unchanged, and the mixed historical
layout is not constructible through it.

Clean merge tree with current main
`e90fe4b8e7c8c819bb51171a43fc94d01b40e2c7`:
`bdbb1029cd3e7ab3a54ac3036d258cd4e6dcbcaa`.
@ddupg
ddupg force-pushed the fix/fts-merge-overlay branch from e0c153a to b57edca Compare November 25, 2026 06:24
Xuanwo pushed a commit that referenced this pull request Nov 25, 2026
…11283)

Split out from #11273.

Arrow permits a null list to span a non-empty range in the child array.
LabelList used the offsets alone when flattening lists, so a label
stored under a null parent could acquire a posting for that row.

Build and update now read each parent row's address once during list
expansion. A valid list pairs its labels with that address. A null list
contributes its address to the list-null bitmap and emits no postings.
The expansion reuses the sliced child array when there are no hidden
values to remove.

The regression test inspects the stored index for both List and
LargeList. It checks that a hidden label has no posting, the null list
is still recorded, and a null element inside a valid list retains its
posting.

All 23 LabelList unit tests passed locally, including both new
regression cases. Formatting passed. Workspace Clippy on macOS arm64
stopped in unchanged byte_stream_split.rs at lines 358 and 393
(unreachable expressions after the NEON dispatch).
Xuanwo pushed a commit that referenced this pull request Nov 30, 2026
…ation (#11274)

Split out from #11273.

Deleting a row leaves its stable ID in the fragment’s row ID sequence.
When a scalar index selects the whole fragment, address-to-ID
translation copies that sequence and includes the deleted row. Selecting
the same physical offsets individually already skips it (#7918).

Apply the fragment’s deletion vector before adding its IDs to the
result. With no deletions, the existing range-based conversion is
unchanged. With deletions, only the deleted offsets need individual
translation.

The regression test deletes ID 7 from a fragment containing IDs 5–9. On
`main`, whole-fragment translation returned `[5, 6, 7, 8, 9]`. With this
change, both selection forms returned `[5, 6, 8, 9]`.

`cargo fmt --all` and Clippy for the `lance` crate (library and tests)
passed. Workspace Clippy on macOS arm64 stops on existing unreachable
expressions in `byte_stream_split.rs` (lines 358 and 393).
@ddupg
ddupg force-pushed the fix/fts-merge-overlay branch from b57edca to 53cf765 Compare December 1, 2026 09:34
@ddupg
ddupg force-pushed the fix/fts-merge-overlay branch from 53cf765 to 65f406b Compare December 2, 2026 01:29

This branch has not been deployed

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

Labels

A-index Vector index, linalg, tokenizer enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: incorporate data overlays when merging scalar index segments

2 participants