Skip to content

[fix](clucene) Support block WAND in composite readers#401

Open
hoshinojyunn wants to merge 1 commit into
apache:clucenefrom
hoshinojyunn:fix/multi-reader-block-wand
Open

[fix](clucene) Support block WAND in composite readers#401
hoshinojyunn wants to merge 1 commit into
apache:clucenefrom
hoshinojyunn:fix/multi-reader-block-wand

Conversation

@hoshinojyunn

@hoshinojyunn hoshinojyunn commented Jul 13, 2026

Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: close apache/doris#62955

Problem Summary: MultiTermDocs did not implement the block postings APIs used by block WAND. Composite readers therefore could not provide block reads, block skipping, or block statistics across child readers. This change implements those APIs, translates child docIDs to global docIDs, handles reader boundaries, and corrects the first-block skip-list sentinel handling in SegmentTermDocs.

Why normalize the skip count?

MultiLevelSkipListReader::skipTo() returns numSkipped - skipInterval - 1. Its negative result is a sentinel meaning no postings have been skipped, not a valid SegmentTermDocs count.

Example with two 2,048-document child readers and a skip interval of 128:

  1. A composite skipToBlock(2085) selects the second child reader and passes local target 37.
  2. The first skip entry covers child-reader docs 0..127. Loading that entry makes numSkipped equal 128, so skipTo(37) returns 128 - 128 - 1 = -1.
  3. The old unconditional assignment set SegmentTermDocs::count to -1. The following readBlock() actually consumes 128 postings, but changes count only to 127, leaving the reader state one posting behind and permitting a later stale or duplicate block read.
  4. Normal skipTo() already avoids this through if (newCount > count). skipToBlock() must instead map its negative sentinel to zero before updating count.

Release note

None

Check List (For Author)

  • Test: Unit Test (./bin/cl_test testReadRange, run three times)
  • Behavior changed: Yes (composite readers support block WAND APIs)
  • Does this need documentation: No

### What problem does this PR solve?

Issue Number: close #62955

Related PR: None

Problem Summary: Implement the block postings API in MultiTermDocs so composite readers globalize block docids, cross child-reader boundaries, and expose block statistics to WAND. Correct SegmentTermDocs handling of the skip-list sentinel returned for the first block, which otherwise lets a subsequent block read consume stale postings. Add MultiReader regression coverage for block reads and cross-reader skip targets.

### Release note

None

### Check List (For Author)

- Test: Unit Test (./bin/cl_test testReadRange)

- Behavior changed: Yes (composite readers support block WAND APIs)

- Does this need documentation: No
@hoshinojyunn hoshinojyunn force-pushed the fix/multi-reader-block-wand branch from dd28de6 to 177dcf8 Compare July 13, 2026 15:31
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.

1 participant