Skip to content

[lsm] get() on a non-unique index resurrects deleted RIDs when tombstone and entry are in different pages #4945

Closed

Description

@lvca

Severity: HIGH (point lookups return deleted rows; disagree with range scans)

Location: index/lsm/LSMTreeIndexAbstract.java:654-655 (lookupInPageAndAddInResultset), callers LSMTreeIndexMutable.searchInNonCompactedIndex:332-353, LSMTreeIndexCompacted.searchInCompactedIndex.

final RidHashSet validRIDs   = new RidHashSet();
final RidHashSet deletedRIDs = new RidHashSet();

Both sets are local to the per-page call; cross-page state is propagated only for unique indexes via removedKeys (:669). For a non-unique index, remove(keys,rid) writes a per-RID tombstone into the current last page while the original entry lives in an older page (or the compacted sub-index). get() walks newest->oldest: the newer page records the tombstone in its local deletedRIDs and discards it on return; the older page starts empty and adds the deleted RID to the result. Deleted entries reappear in WHERE prop = x index lookups. The cursor path handles this correctly via cross-cursor ridState, so point lookups and range scans disagree on the same data. validRIDs is dead code.

Fix: hoist deletedRIDs to the caller and thread it through searchInNonCompactedIndex -> lookupInPageAndAddInResultset -> searchInCompactedIndex, like removedKeys; delete validRIDs. Regression test: non-unique index, tombstone in a later page (or compacted), get(K) must be empty.


Filed from an internal engine deep-audit (2026-07). Traced to source; verify against current main before fixing and add a regression test.

Activity

  1. added
    audit
    on Jul 4, 2026
  2. added this to the 26.8.1 milestone on Jul 4, 2026
  3. added a commit that references this issue on Jul 4, 2026
  4. lvca commented on Jul 5, 2026

    @lvca
    MemberAuthor

    Fixed in #4968 (merged). Reproduced: on a non-unique index, get() resurrected a deleted RID whenever the per-RID tombstone and the original ADD lived in different pages, because the deletedRIDs set was local to each page lookup while removedKeys (the unique-index whole-key tombstone set) was already threaded across pages.

    deletedRIDs is now threaded through searchInNonCompactedIndex -> lookupInPageAndAddInResultset -> searchInCompactedIndex, exactly like removedKeys, so point lookups agree with the range/cursor path.

  5. added a commit that references this issue on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    auditbugopencyphersql

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions