CNDB-15485: Fix ResultRetriever key comparison to prevent dupes in result set #2024
+18
−3
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.
(cherry picked from commit ada025c)
Copy of #2023, but targeting
main
What is the issue
https://github.com/riptano/cndb/issues/15485
What does this PR fix and why was it fixed
This PR fixes a bug introduced to this branch via #1884. The bug only impacts SAI file format
aa
when the index file was produced via compaction, which is why the modified test simply adds coverage to compact the table and hit the bug.The bug happens when an iterator produces the same partition across two different batch fetches from storage. These keys were not collapsed in the
key.equals(lastKey)
logic because compacted indexes use a row id per row instead of per partition, and the logic inPrimaryKeyWithSource
considers rows with different row ids to be distinct. However, when we went to materialize a batch from storage, we hit this code:which returned
clusteringIndexFilter
foraa
because those indexes do not have the clustering information. Therefore, each batch fetched the whole partition (which was subsequently filtered to the proper results), and produced a multiplier effect where we sawbatch
many duplicates.This fix works by comparing partition keys and clustering keys directly, which is a return to the old comparison logic from before #1884. There was actually a discussion about this in the PR to
main
, but unfortunately, we missed this case #1883 (comment).A more proper long term fix might be to remove the logic of creating a
PrimaryKeyWithSource
for AA indexes. However, I preferred this approach because it is essentially arevert
instead of fixing forward solution.