Skip to content

branch-4.2: [fix](inverted index) Share BM25 statistics across parallel scanners of a tablet #69352 - #69440

Merged
yiguolei merged 1 commit into
apache:branch-4.2from
guptashivam04:backport/4.2-bm25-tablet-statistics
Oct 23, 2026
Merged

yiguolei merged 1 commit into
apache:branch-4.2from
guptashivam04:backport/4.2-bm25-tablet-statistics

Conversation

@guptashivam04

Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: None

Related PR: #69352

Problem Summary:

Backport of #69352 to branch-4.2.

A parallel scan (ParallelScannerBuilder) splits one tablet into several scanners. Each OlapScanner then calls CollectionStatistics::collect() with only the rs_splits of its own split, so the BM25 doc count, avgdl and term doc frequencies come from a subset of the tablet's rowsets. Rows with identical text get different scores depending on which scanner reads them. Because the split depends on the tablet's row count and the core count, a row's score and its rank in ORDER BY score() change when unrelated rows are loaded, and pagination over a score-ordered search returns repeated and missing rows.

Fix (same as #69352):

  • TabletCollectionStatistics holds the rowsets of a tablet's entire read source. The first scanner of the tablet to prepare collects the statistics once with collect_full_collection(), and every scanner of that tablet copies them into its own CollectionStatistics. Later scanners wait for the first collection and get its result or error.
  • CollectionStatistics::copy_collected_from() copies the collected counters and resets the derived idf/avgdl caches, so no cache is shared between scanner threads.
  • ParallelScannerBuilder creates one holder per tablet, only when the scan has a score() runtime. Both the by-rowid and by-segment build paths pass it to their scanners through OlapScanner::Params.
  • The non-parallel path is unchanged. Each of its scanners already receives the tablet's full read source.

Differences from #69352: branch-4.2 does not have the changelog, TSO and bucket fields of OlapScanner::Params or the scan_range argument of _build_scanner, so the scanner changes were applied by hand on top of the branch-4.2 code. OlapScanner::Params is initialized positionally on this branch, so the new field is appended at the end. branch-4.2 has no test that calls _build_scanner directly, so the follow-up test fix from #69352 is not needed here.

Statistics remain per tablet. Making them consistent across tablets and BEs is out of scope.

Release note

Fix BM25 score() returning different scores for identical rows of the same tablet when a parallel scan split the tablet into several scanners.

Check List (For Author)

  • Test

  • Behavior changed:

    • Yes. Score queries that use a parallel scan now score every row of a tablet against statistics of the whole tablet. Scores can differ from earlier releases but are now independent of the scanner split.
  • Does this need documentation?

    • No.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

…el scanners of a tablet apache#69352

A parallel scan splits one tablet into several scanners, and each scanner
collected BM25 statistics (doc count, avgdl, term doc freqs) over only the
rowsets in its own split. Rows with identical text therefore got different
scores depending on which scanner read them, and because the split depends
on the tablet's row count and the core count, a row's score and rank moved
whenever unrelated data was loaded.

Collect the statistics once per tablet over its entire read source and copy
them into each scanner, so every row of a tablet is scored against the same
idf and avgdl. Each scanner keeps its own copy, so the per-scanner idf/avgdl
caches are not shared between threads.
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@yiguolei

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 36.07% (22/61) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 64.27% (29899/46523)
Line Coverage 49.12% (315379/642116)
Region Coverage 44.98% (254115/564971)
Branch Coverage 46.61% (119899/257247)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 96.72% (59/61) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.39% (34513/45182)
Line Coverage 61.23% (389846/636737)
Region Coverage 58.15% (329086/565884)
Branch Coverage 59.04% (151717/256955)

@yiguolei
yiguolei merged commit 7ad1367 into apache:branch-4.2 Oct 23, 2026
28 of 29 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

PR approved by anyone and no changes requested.

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Oct 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR approved by at least one committer and no changes requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants