fix: keep row ids and addresses aligned in filter_deleted_ids#7776
Open
chakshu-dhannawat wants to merge 1 commit into
Open
fix: keep row ids and addresses aligned in filter_deleted_ids#7776chakshu-dhannawat wants to merge 1 commit into
chakshu-dhannawat wants to merge 1 commit into
Conversation
optimize_indices could fail with "batch.num_rows() != chunk.len()" after deleting rows from a stable-row-id dataset indexed with IVF_FLAT. When stable row ids are enabled, deleting rows also removes them from the row id index, so those ids no longer resolve to an address. filter_deleted_ids built the address list with a filter_map, which silently dropped the unresolvable ids and left the addresses vec shorter than the ids vec. It then handed the full ids vec plus the shortened addresses vec to filter_addr_or_ids, which relies on the two being positionally aligned (it sorts the addresses, checks each against its fragment's deletion vector, then zips the result back against the input ids). Once the lengths diverge the zip pairs ids with the wrong liveness verdict, so some already-deleted ids get reported as live. take_vectors then asks take_rows for those ids, gets back fewer rows than the chunk it requested, and errors out. Build ids and addresses together and unzip them so the two slices stay the same length and positionally correspond. Ids that no longer resolve are dropped from both, which is correct since those rows are already gone. Fixes lance-format#7701
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
optimize_indicesfails withInvalid user input: batch.num_rows() != chunk.len()after deleting rows from a stable-row-id dataset that has an IVF_FLAT index. Reported in #7701.Repro (from the issue):
Root cause
When stable row ids are enabled, deleting rows also removes them from the row id index (
decompose_segment_with_deletionsskips deleted offsets), so those ids no longer resolve to an address.filter_deleted_idsbuilt its address list with afilter_map:The
filter_mapsilently drops the unresolvable ids, soaddressesends up shorter thanids.filter_addr_or_idsthen receives the fullidsslice alongside the shortenedaddressesslice, but it relies on the two being positionally aligned: it sorts the addresses, checks each one against its fragment's deletion vector, un-sorts, and zips the liveness result back against the input ids. Once the lengths diverge the zip pairs ids with the wrong verdict, so some already-deleted ids get reported as live. During anoptimize_indicespartition join,take_vectorsaskstake_rowsfor those ids, gets back fewer rows than the chunk it requested, and hits thebatch.num_rows() != chunk.len()check.Fix
Build
idsandaddressestogether andunzipthem, so the two slices stay the same length and positionally correspond. Ids that no longer resolve are dropped from both, which is correct since those rows are already gone.Testing
Added
optimize_after_delete_with_stable_row_ids_joins_partitionsinrust/lance/src/index/vector/builder.rs, which ports the repro: stable row ids + IVF_FLAT (16 partitions) + delete +optimize_indices, then checks the surviving row count and that a search over the optimized index returns only live rows. It reproduces the exact original error (batch.num_rows() != chunk.len() (188 != 235)) on the unfixed code and passes with the fix. The existingbuilder(55) androwids(16) test suites still pass;cargo fmtandcargo clippy -p lance --tests -- -D warningsare clean.Summary by CodeRabbit
Bug Fixes
Tests