Repository navigation
perf: avoid cloning deletion masks when the prefilter only has deletions - #10403
Conversation
When a vector search has no query filter, no FTS fragment pruning and no overlay block, the prefilter only removes deleted rows. Two places still copied a mask in that case: - `DatasetPreFilter::wait_for_ready` ANDed the deletion mask into an empty `RowAddrMask::default()` (selects all rows), cloning the whole dataset-wide deletion mask on every query. - `SegmentPreFilter::wait_for_ready` cloned that dataset-wide mask again for every index segment and intersected it with the segment's ownership mask. The ownership mask is the allow list of the live rows of the segment's fragments at the dataset's current version, so with a deletions-only base the intersection is the ownership mask itself. Share the existing masks instead of copying them. On a 6.8B-row table with 99,020 fragments, 153 index segments and 10% rows deleted, a steady-state k=10 search drops from 66 s to 35 s; on the same table after compaction (no deletion files, retired fragment ids) it drops from 0.70 s to 0.17 s. Results are unchanged.
|
@claude review |
Without stable row ids, every vector search rebuilds the dataset-wide deletion mask: it walks every fragment with a deletion file, converts each deletion vector into a bitmap and merges them. Deletion files of a version are immutable, so the result only depends on the version and the fragment set. The stable-row-id path already caches its mask under `RowAddrMaskKey`; the address path did not. Cache the address mask the same way, in the metadata cache, keyed by (version, manifest e-tag, fragment-set hash, restricted or not). As on the row-id path, a dataset without an e-tag is not cached, because a dataset recreated at the same URI restarts at the same version numbers. On a 6.8B-row table with 99,020 fragments (all with deletion files), 153 index segments and 10% rows deleted, this eliminates the ~35 s per-query mask reconstruction overhead; combined with lance-format#10403, steady-state k=10 search drops from 66 s to 0.37 s, versus 0.30 s on the same data files without deletions. Results are unchanged.
|
Regarding the It is parameterized over
All 4 parameter combinations pass locally ( |
…r-10403-merge-20261101
…r-10403-merge-20261101
Xuanwo
left a comment
There was a problem hiding this comment.
Approved for merge. Deletions-only mask sharing matches the accepted semantics on current main; final-head targeted regressions, fmt, full ci-profile Clippy, current-head Gatekeeper, format vote, metadata gates, module-size, typo and license checks pass, with Linux workspace, Python and Java JNI coverage reused for the verified version-only main update.
Part of #10402. (Independent of #10404; can be reviewed and merged in either order.)
Problem
When a vector search has no scalar query filter (
filtered_ids), no FTS fragment pruning (deleted_fragments), and nooverlay_block,DatasetPreFilteronly removes deleted rows. However, the current implementation still clones and intersectsRowAddrMaskin two places on every query:DatasetPreFilter::wait_for_ready(rust/lance/src/index/prefilter.rs):Intersects
deleted_idswithRowAddrMask::default()(an empty block-list that selects every row):When
deleted_idsis the only active filter, this clones the entire dataset-wide deletion mask on every query only to produce the deletion mask itself.SegmentPreFilter::wait_for_ready(rust/lance/src/io/exec/knn.rs):Clones both the dataset-wide base mask and the segment's
ownership_maskfor every index segment to compute their intersection:self.ownership_mask(built bycreate_restricted_deletion_maskand cached underSegmentOwnershipMaskKeyby dataset version ande_tag) is already an allow-list of the live rows belonging to that segment's fragments at the current dataset version. Whenself.baseonly filters deletions,ownership_maskis already a subset ofself.base.mask(), so their intersection is identical toownership_maskitself.This also affects compacted tables with zero deletion files: when fragment IDs have gaps (
needs_restriction == true),create_deletion_mask_implbuilds a live-row allow-list across all fragments, whichSegmentPreFilterthen clones into every segment on each query.Solution
DatasetPreFilter::only_deletions(&self) -> bool, which returnstruewhenfiltered_ids,deleted_fragments, andoverlay_blockare allNone. It destructuresSelfso adding any new filter field toDatasetPreFilterfails to compile until accounted for.DatasetPreFilter::wait_for_ready, returndeleted_ids.get_ready()directly whenself.only_deletions()istrue.SegmentPreFilter::wait_for_ready, returnself.ownership_mask.clone()(Arcclone) directly whenself.base.only_deletions()istrue.Benchmark
Steady-state
k=10, nprobes=1latency on a 6.8B-row dataset (99,020fragments,153IVF segments,metadata_cache_size_bytes=48 GiB,index_cache_size_bytes=96 GiB; see #10402 for full details):main(Companion PR #10404 caches the address-based deletion mask per dataset version, eliminating the remaining ~35 s reconstruction cost and bringing the 10.4%-deleted case down to
0.37 swhen both PRs are applied.)Tests
test_vector_search_excludes_rows_deleted_after_indexing(dataset/tests/dataset_index.rs): end-to-end regression test parameterized overuse_stable_row_id in [false, true]×compact in [false, true](builds 2 IVF segments, deletes rows post-indexing, runscompact_filesto retire fragment IDs and deletes again in the compacted cases, and probes all partitions withkabove total row count to assert the returned rows equal the exact set of live rows).test_deletions_only_prefilter_shares_mask(index/prefilter.rs): verifies viaArc::ptr_eqthat a deletions-onlyDatasetPreFiltershares thedeleted_idsArc.test_append_only_deltas_keep_empty_prefilter_fast_path(io/exec/knn.rs): verifies viaArc::ptr_eqthatSegmentPreFilterreusesownership_maskdirectly.Integration
The benchmark table above was measured on PR head
f7427c4e4899against its original base; it was not rerun. The final integrated headb1bac4f4a041becc2aaf9afdfb00e809c31b7b92includesmainatf56a08d40b5630ce1124535c4c3b1406d5ceedf1; the merge preserves the mask-sharing path, original regression assertions and the15.0.0-beta.10release stamp only.