Skip to content

db/recsplit/eliasfano32: fix searchUpperReverse off-by-one on no-solution fast path#20566

Merged
AskAlexSharov merged 3 commits intomainfrom
alex/eliasfano-seek-cr-fixes
Apr 15, 2026
Merged

db/recsplit/eliasfano32: fix searchUpperReverse off-by-one on no-solution fast path#20566
AskAlexSharov merged 3 commits intomainfrom
alex/eliasfano-seek-cr-fixes

Conversation

@AskAlexSharov
Copy link
Copy Markdown
Collaborator

Fixes CR comment from #19788.

In searchUpperReverse, the n <= 0 fast path (when hiIdx == lo) returned lo, causing searchReverse to still probe idx=0 on guaranteed-miss queries. The correct return is lo + 1, mirroring searchUpperForward and ensuring the caller loop is skipped entirely when there is no solution.

…tion fast path

Return lo+1 instead of lo in the n<=0 branch of searchUpperReverse to mirror
searchUpperForward behavior. When hiIdx==lo the answer is past the bracket
(guaranteed miss), so returning lo caused searchReverse to probe idx=0
unnecessarily instead of skipping the loop entirely.
…corner case

TestSearchUpperReverseNoSolution directly asserts that searchUpperReverse returns
count+1 (not count) when all upper bits exceed hi, ensuring the caller loop in
searchReverse is skipped. The test fails against the pre-fix code that returned lo.
Copy link
Copy Markdown
Collaborator

@Giulio2002 Giulio2002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM \u2014 small, straightforward change with low review risk

@AskAlexSharov AskAlexSharov added this pull request to the merge queue Apr 15, 2026
Merged via the queue into main with commit 39b4aac Apr 15, 2026
36 checks passed
@AskAlexSharov AskAlexSharov deleted the alex/eliasfano-seek-cr-fixes branch April 15, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants