Skip to content

[fix](inverted index) Split bound multi-segment readers#63138

Open
airborne12 wants to merge 1 commit into
apache:masterfrom
airborne12:doris-25499-multireader-master
Open

[fix](inverted index) Split bound multi-segment readers#63138
airborne12 wants to merge 1 commit into
apache:masterfrom
airborne12:doris-25499-multireader-master

Conversation

@airborne12
Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: DORIS-25499

Related PR: None

Problem Summary:
query_v2 search collection can drive segment iteration from readers.front() while leaf scorers resolve CLucene readers from reader_bindings or field_reader_bindings. If the actual leaf reader remains a multi-segment reader, SegmentPostings calls TermDocs::readBlock(), which CLucene does not support for multi-segment readers and can abort BE.

This PR selects the actual segmented reader from the execution context, rewrites all readers and reader bindings to segment-level readers for each callback, validates segmented reader topology, and keeps MultiSegmentReader / MultiReader doc base handling explicit. It also adds regression coverage for MultiReader, segmented field bindings, and explicit single-reader binding keys.

Release note

None

Check List (For Author)

  • Test

    • Regression test
      • Added MultiSegmentCollectorTest.CollectDocSetWithMultiReader
      • Added MultiSegmentCollectorTest.CollectDocSetWithSegmentedFieldBinding
      • Added MultiSegmentCollectorTest.CollectDocSetWithSingleReaderBinding
    • Unit Test
      • env CCACHE_DIR=/tmp/doris25499-master-ccache CCACHE_TEMPDIR=/tmp/doris25499-master-ccache-tmp ./run-be-ut.sh --run --filter=MultiSegmentCollectorTest.* -j 32
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

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

@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?

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: query_v2 search collection could pick the segment loop from readers.front() while leaf scorers resolved CLucene readers from reader_bindings or field_reader_bindings. SegmentPostings requires segment-level readers because multi-segment TermDocs::readBlock() is unsupported.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - env CCACHE_DIR=/tmp/doris25499-master-ccache CCACHE_TEMPDIR=/tmp/doris25499-master-ccache-tmp ./run-be-ut.sh --run --filter=MultiSegmentCollectorTest.* -j 32
- Behavior changed: No
- Does this need documentation: No
@airborne12 airborne12 force-pushed the doris-25499-multireader-master branch from 7d22250 to 81370a7 Compare May 18, 2026 07:10
@airborne12
Copy link
Copy Markdown
Member Author

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 31274 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 81370a7048d2f46231cc36cce37b24d641ec36c4, data reload: false

------ Round 1 ----------------------------------
orders	Doris	NULL	NULL	0	0	0	NULL	0	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	17958	3915	3864	3864
q2	q3	10818	1344	798	798
q4	4703	475	354	354
q5	7654	2260	2113	2113
q6	242	175	141	141
q7	930	792	634	634
q8	9403	1668	1667	1667
q9	5176	4915	4893	4893
q10	6406	2047	1801	1801
q11	433	281	249	249
q12	631	429	294	294
q13	18083	3366	2791	2791
q14	265	257	236	236
q15	q16	810	769	701	701
q17	979	913	942	913
q18	6861	5915	5571	5571
q19	1323	1364	1042	1042
q20	518	571	309	309
q21	6184	2821	2569	2569
q22	471	499	334	334
Total cold run time: 99848 ms
Total hot run time: 31274 ms

----- Round 2, with runtime_filter_mode=off -----
orders	Doris	NULL	NULL	150000000	42	6422171781	NULL	22778155	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	4714	4570	4609	4570
q2	q3	4918	5232	4689	4689
q4	2243	2227	1426	1426
q5	4935	4707	4598	4598
q6	223	191	147	147
q7	1944	1734	1610	1610
q8	2375	2033	2074	2033
q9	7659	7196	7221	7196
q10	4504	4438	4014	4014
q11	535	383	359	359
q12	718	727	515	515
q13	3066	3403	2798	2798
q14	274	285	256	256
q15	q16	674	703	601	601
q17	1272	1231	1222	1222
q18	7263	6914	6811	6811
q19	1123	1110	1087	1087
q20	2208	2229	1928	1928
q21	5349	4610	4486	4486
q22	541	449	404	404
Total cold run time: 56538 ms
Total hot run time: 50750 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 170112 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 81370a7048d2f46231cc36cce37b24d641ec36c4, data reload: false

query5	4326	678	529	529
query6	330	224	202	202
query7	4265	538	319	319
query8	338	253	227	227
query9	8851	4055	4026	4026
query10	460	344	285	285
query11	5778	2485	2201	2201
query12	178	128	120	120
query13	1267	612	425	425
query14	6099	5423	5082	5082
query14_1	4376	4399	4376	4376
query15	216	198	182	182
query16	1006	472	424	424
query17	1047	748	602	602
query18	2464	497	369	369
query19	227	209	171	171
query20	139	135	131	131
query21	221	148	119	119
query22	13727	13644	13321	13321
query23	17194	16384	16019	16019
query23_1	16272	16185	16124	16124
query24	7661	1788	1324	1324
query24_1	1311	1344	1318	1318
query25	574	508	450	450
query26	1309	318	174	174
query27	2748	550	344	344
query28	4446	1992	1947	1947
query29	1015	652	549	549
query30	324	243	201	201
query31	1134	1065	951	951
query32	94	79	79	79
query33	566	384	304	304
query34	1207	1109	668	668
query35	783	791	683	683
query36	1296	1359	1168	1168
query37	165	110	97	97
query38	3235	3174	3056	3056
query39	941	921	906	906
query39_1	875	900	895	895
query40	241	159	132	132
query41	72	71	71	71
query42	118	120	118	118
query43	343	340	301	301
query44	
query45	220	203	200	200
query46	1077	1203	756	756
query47	2271	2299	2185	2185
query48	425	418	305	305
query49	650	505	404	404
query50	1016	361	258	258
query51	4320	4267	4248	4248
query52	109	110	98	98
query53	272	291	207	207
query54	368	284	255	255
query55	94	88	85	85
query56	320	298	311	298
query57	1428	1393	1309	1309
query58	304	267	272	267
query59	1557	1605	1391	1391
query60	328	313	323	313
query61	157	165	151	151
query62	664	621	549	549
query63	244	202	203	202
query64	2411	821	632	632
query65	
query66	1724	485	346	346
query67	30071	30039	29848	29848
query68	
query69	455	350	315	315
query70	1016	1012	1029	1012
query71	308	281	274	274
query72	3053	2714	2491	2491
query73	855	795	425	425
query74	5097	4924	4716	4716
query75	2654	2595	2263	2263
query76	2287	1153	816	816
query77	412	424	345	345
query78	12266	12095	11646	11646
query79	1498	1014	748	748
query80	677	559	457	457
query81	459	278	239	239
query82	1362	158	128	128
query83	361	296	249	249
query84	294	139	115	115
query85	892	548	460	460
query86	401	324	324	324
query87	3470	3345	3214	3214
query88	3627	2667	2647	2647
query89	441	382	339	339
query90	1980	184	189	184
query91	184	168	139	139
query92	81	78	77	77
query93	1547	1434	905	905
query94	584	357	298	298
query95	676	393	432	393
query96	1026	791	332	332
query97	2703	2669	2575	2575
query98	240	228	229	228
query99	1122	1121	968	968
Total cold run time: 254212 ms
Total hot run time: 170112 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 91.59% (98/107) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 63.43% (23973/37797)
Line Coverage 47.11% (246775/523785)
Region Coverage 44.08% (202729/459939)
Branch Coverage 45.38% (87761/193406)

1 similar comment
@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 91.59% (98/107) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 63.43% (23973/37797)
Line Coverage 47.11% (246775/523785)
Region Coverage 44.08% (202729/459939)
Branch Coverage 45.38% (87761/193406)

@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 91.59% (98/107) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 63.43% (23975/37797)
Line Coverage 47.13% (246846/523785)
Region Coverage 44.13% (202987/459939)
Branch Coverage 45.37% (87753/193406)

@airborne12
Copy link
Copy Markdown
Member Author

/review

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Requesting changes due to a remaining correctness/crash path in query_v2 multi-segment handling.

Critical checkpoint conclusions:

  • Goal/test: The PR addresses multi-segment reader splitting for collection and adds BE unit coverage for doc-set collection, but it does not cover or fix null-bitmap extraction after collection.
  • Scope/focus: The change is focused, but the fix is incomplete because one downstream scorer-building path bypasses the new segment iterator.
  • Concurrency/lifecycle: No new concurrency or non-obvious static lifecycle issue found. The non-owning subreader wrappers are used within the parent reader lifetime during collection.
  • Compatibility/config/persistence: No config, protocol, storage-format, or persistence compatibility concern found.
  • Parallel paths: A parallel query_v2 path remains: FunctionSearch extracts null bitmaps by building a scorer on the original context after collection.
  • Tests: Added tests cover doc-set collection for MultiReader and bindings, but not top-k/WAND or null-bearing queries; the missing null case is directly related to the remaining issue.
  • Observability/performance: No additional observability issue found; no clear performance regression beyond small per-segment context creation.

User focus: No additional user-provided review focus was supplied.

template <typename SegmentCallback>
void for_each_index_segment(const QueryExecutionContext& context, const std::string& binding_key,
SegmentCallback&& callback) {
auto* reader = context.readers.empty() ? nullptr : context.readers.front().get();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This only fixes callers that go through for_each_index_segment, but FunctionSearch::evaluate_inverted_index_with_search_param still extracts NULLs after collection with weight->scorer(exec_ctx, root_binding_key) on the original exec_ctx (see the exec_ctx.null_resolver block after the collector call). Term/boolean scorers construct SegmentPostings immediately via create_term_posting(), so a query over a nullable field whose reader is MultiReader/MultiSegmentReader can still reach the same unsupported multi-segment TermDocs::readBlock() path after collection succeeds. Please route null-bitmap extraction through segment contexts as well, or otherwise avoid building SegmentPostings on the unsplit multi-segment reader, and add a nullable multi-segment test for this path.

Copy link
Copy Markdown
Member

@eldenmoon eldenmoon left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label May 19, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants