Repository navigation
branch-4.2: [fix](inverted index) Share BM25 statistics across parallel scanners of a tablet #69352 - #69440
Merged
yiguolei merged 1 commit intoOct 23, 2026
Conversation
…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.
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
|
run buildall |
Contributor
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
Contributor
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
yiguolei
approved these changes
Oct 23, 2026
Contributor
|
PR approved by anyone and no changes requested. |
Contributor
|
PR approved by at least one committer and no changes requested. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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. EachOlapScannerthen callsCollectionStatistics::collect()with only thers_splitsof 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 inORDER BY score()change when unrelated rows are loaded, and pagination over a score-ordered search returns repeated and missing rows.Fix (same as #69352):
TabletCollectionStatisticsholds the rowsets of a tablet's entire read source. The first scanner of the tablet to prepare collects the statistics once withcollect_full_collection(), and every scanner of that tablet copies them into its ownCollectionStatistics. 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.ParallelScannerBuildercreates one holder per tablet, only when the scan has ascore()runtime. Both the by-rowid and by-segment build paths pass it to their scanners throughOlapScanner::Params.Differences from #69352: branch-4.2 does not have the changelog, TSO and bucket fields of
OlapScanner::Paramsor thescan_rangeargument of_build_scanner, so the scanner changes were applied by hand on top of the branch-4.2 code.OlapScanner::Paramsis initialized positionally on this branch, so the new field is appended at the end. branch-4.2 has no test that calls_build_scannerdirectly, 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
Regression test:
inverted_index_p0/test_bm25_score_parallel_scan_statistics(same suite as [fix](inverted index) Share BM25 statistics across parallel scanners of a tablet #69352). Passes on branch-4.2 with this change.Unit Test:
CollectionStatisticsDetailedTest.CopyCollectedFromScoresLikeSource,TabletCollectionStatisticsTest.CollectsOnceAndCopiesToEveryCaller(compiled locally; run left to CI)Manual test: ran the reproduction from [fix](inverted index) Share BM25 statistics across parallel scanners of a tablet #69352 against branch-4.2 builds on macOS arm64.
enable_parallel_scan=true(split forced)enable_parallel_scan=falsea5d2661d, without this changea5d2661dwith this changeNo need to test or manual test.
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)