Skip to content

[improvement](topn) Add option to skip file cache writes in topn lazy materialization#65021

Open
bobhan1 wants to merge 3 commits into
apache:masterfrom
bobhan1:doris-topn-phase2-no-write-cache
Open

[improvement](topn) Add option to skip file cache writes in topn lazy materialization#65021
bobhan1 wants to merge 3 commits into
apache:masterfrom
bobhan1:doris-topn-phase2-no-write-cache

Conversation

@bobhan1

@bobhan1 bobhan1 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds an opt-in session variable for TopN lazy materialization phase-2 file-cache miss handling.

  • add enable_topn_lazy_mat_phase2_no_write_file_cache
  • keep the option disabled by default, so existing behavior is unchanged
  • when the option is enabled, phase-2 lazy materialization uses already-downloaded file-cache blocks for full local hits and reads remote data directly on cache miss without writing the file cache
  • expose aggregate and per-BE phase-2 rows, segments, and file-cache counters in the MaterializeNode profile
  • accumulate per-BE stats across multiple phase-2 fetch calls
  • cover both row-store and column-store fetch paths

Validation

  • ./build.sh --be --fe --cloud -j100
  • before packaging, verified no output/fe/conf/fe_custom.conf, no output/be/conf/be_custom.conf, empty output/fe/doris-meta, and empty output/be/storage
  • for docker regression image, verified FE/BE debug-point config and BE Java support config:
    • output/fe/conf/fe.conf: enable_debug_points=true
    • output/be/conf/be.conf: enable_debug_points=true, enable_java_support=false
  • env -u HTTP_PROXY -u HTTPS_PROXY -u http_proxy -u https_proxy -u ALL_PROXY -u all_proxy ./run-regression-test.sh --run -d cloud_p0/cache/topn_lazy_file_cache -s test_topn_lazy_mat_phase2_no_write_file_cache -g docker -runMode=cloud -dockerSuiteParallel 1
    • Test 1 suites, failed 0 suites, fatal 0 scripts, skipped 0 scripts
  • ./run-be-ut.sh --run --filter=MaterializationSharedStateTest.*:BlockFileCacheTest.get_downloaded_blocks_if_fully_covered_is_read_only:BlockFileCacheTest.cached_remote_file_reader_remote_only_on_miss
    • 7 tests from 2 test suites ran
    • PASSED 7 tests
  • ./run-be-ut.sh --run --filter=BlockFileCacheTest.cached_remote_file_reader_remote_only_on_miss:BlockFileCacheTest.fd_cache_remove:BlockFileCacheTest.fd_cache_evict
    • 3 tests from 1 test suite ran
    • PASSED 3 tests

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

@bobhan1 bobhan1 force-pushed the doris-topn-phase2-no-write-cache branch 2 times, most recently from e33b38c to 59e4e37 Compare June 30, 2026 09:12
bobhan1 added 2 commits July 2, 2026 10:25
Issue Number: None

Related PR: None

Problem Summary: TopN lazy materialization phase 2 may populate file cache while fetching deferred columns. This can pollute cache when the requested ranges are cache misses. Add a cloud-only session switch for the new PMultiGetRequestV2 path so phase-2 reads use cached blocks only when the full range is already downloaded, and otherwise read remote data directly without writing file cache. The change also exposes phase-2 file-cache counters in the MaterializeNode profile and covers row-store and column-store fetch paths.

Added session variable `enable_topn_lazy_mat_phase2_no_write_file_cache` to avoid file-cache writes on TopN lazy materialization phase-2 cache misses.

- Test:
    - Unit Test: ./run-be-ut.sh --run --filter=BlockFileCacheTest.get_downloaded_blocks_if_fully_covered_is_read_only:BlockFileCacheTest.cached_remote_file_reader_remote_only_on_miss -j20
    - Build: ./build.sh --be --fe --cloud -j100
    - Format: build-support/check-format.sh
    - Regression test: env -u HTTP_PROXY -u HTTPS_PROXY -u http_proxy -u https_proxy -u ALL_PROXY -u all_proxy ./run-regression-test.sh --run -d cloud_p0/cache/topn_lazy_file_cache -s test_topn_lazy_mat_phase2_no_write_file_cache -g docker -runMode=cloud -dockerSuiteParallel 1
- Behavior changed: Yes. When the new session variable is enabled in cloud mode, TopN lazy materialization phase-2 cache misses read remote data without writing file cache.
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: TopN lazy materialization phase 2 exposed only aggregated profile counters, which makes backend-level skew and IO differences hard to identify when phase-2 fetch fans out to multiple backends. Add aggregate rows/segments counters and per-backend rows, segments, and file-cache statistics for the new TopN lazy materialization V2 path. The per-backend values are accumulated in MaterializationSharedState so multiple phase-2 fetch calls in one query are reflected in the final profile.

### Release note

Added per-backend TopN lazy materialization phase-2 profile counters.

### Check List (For Author)

- Test:
    - Build: ./build.sh --be --fe --cloud -j100
    - Format: build-support/clang-format.sh; build-support/check-format.sh; git diff --check
    - Regression test: env -u HTTP_PROXY -u HTTPS_PROXY -u http_proxy -u https_proxy -u ALL_PROXY -u all_proxy ./run-regression-test.sh --run -d cloud_p0/cache/topn_lazy_file_cache -s test_topn_lazy_mat_phase2_no_write_file_cache -g docker -runMode=cloud -dockerSuiteParallel 1
- Behavior changed: Yes. TopN lazy materialization phase-2 profiles now include aggregate row/segment counts and per-backend detail counters.
- Does this need documentation: No
@bobhan1 bobhan1 force-pushed the doris-topn-phase2-no-write-cache branch from 59e4e37 to a7efbdf Compare July 2, 2026 03:38
@bobhan1 bobhan1 marked this pull request as ready for review July 2, 2026 03:41
@bobhan1 bobhan1 changed the title [improvement](topn) Avoid file cache writes in lazy materialization [improvement](topn) Add option to skip file cache writes in lazy materialization Jul 2, 2026
@bobhan1 bobhan1 changed the title [improvement](topn) Add option to skip file cache writes in lazy materialization [improvement](topn) Add option to skip file cache writes in topn lazy materialization Jul 2, 2026
@bobhan1

bobhan1 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

@bobhan1

bobhan1 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

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.

Automated review completed. I found one issue in the TopN lazy materialization file-cache policy propagation.

Comment thread be/src/exec/rowid_fetcher.cpp
@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17799	4070	3974	3974
q2	2003	326	200	200
q3	10846	1451	830	830
q4	4769	474	340	340
q5	8657	864	589	589
q6	364	173	134	134
q7	857	849	629	629
q8	10704	1580	1537	1537
q9	5901	4420	4458	4420
q10	6868	1786	1523	1523
q11	509	345	313	313
q12	738	553	434	434
q13	18111	3310	2729	2729
q14	263	267	241	241
q15	q16	793	773	711	711
q17	1055	983	1008	983
q18	7119	5893	5562	5562
q19	1181	1258	989	989
q20	791	683	560	560
q21	5619	2698	2477	2477
q22	433	362	294	294
Total cold run time: 105380 ms
Total hot run time: 29469 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4361	4269	4281	4269
q2	290	315	214	214
q3	4555	4974	4368	4368
q4	2052	2144	1369	1369
q5	4403	4283	4523	4283
q6	297	210	140	140
q7	2186	1773	1589	1589
q8	2461	2124	2137	2124
q9	7807	7750	7774	7750
q10	4743	4718	4481	4481
q11	610	409	374	374
q12	727	739	594	594
q13	3194	3513	2982	2982
q14	316	296	272	272
q15	q16	735	759	673	673
q17	1343	1321	1319	1319
q18	8056	7494	6955	6955
q19	1149	1080	1115	1080
q20	2231	2198	1911	1911
q21	5222	4546	4445	4445
q22	510	467	406	406
Total cold run time: 57248 ms
Total hot run time: 51598 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 174136 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 a7efbdf8e07f4dc60d62c9f91c612ac1f468e477, data reload: false

query5	4323	647	498	498
query6	463	217	203	203
query7	4843	619	342	342
query8	340	184	170	170
query9	8749	4017	4014	4014
query10	461	354	307	307
query11	5854	2336	2124	2124
query12	157	110	116	110
query13	1308	603	443	443
query14	6284	5282	4952	4952
query14_1	4303	4323	4282	4282
query15	211	207	182	182
query16	1016	484	449	449
query17	1133	741	618	618
query18	2480	487	351	351
query19	212	202	170	170
query20	117	113	108	108
query21	234	155	138	138
query22	13515	13583	13344	13344
query23	17378	16564	16142	16142
query23_1	16377	16215	16255	16215
query24	7596	1770	1292	1292
query24_1	1313	1299	1320	1299
query25	595	472	410	410
query26	1332	349	213	213
query27	2659	579	379	379
query28	4459	2021	2014	2014
query29	1090	641	504	504
query30	340	265	234	234
query31	1127	1099	996	996
query32	115	71	71	71
query33	525	333	272	272
query34	1192	1106	656	656
query35	776	787	677	677
query36	1438	1402	1252	1252
query37	154	110	97	97
query38	1881	1720	1648	1648
query39	940	921	943	921
query39_1	888	882	869	869
query40	241	165	147	147
query41	66	64	65	64
query42	92	93	88	88
query43	319	318	277	277
query44	1406	780	760	760
query45	199	195	179	179
query46	1077	1202	759	759
query47	2409	2393	2232	2232
query48	400	408	287	287
query49	596	427	321	321
query50	1040	425	320	320
query51	4490	4533	4419	4419
query52	87	85	73	73
query53	260	287	205	205
query54	273	226	215	215
query55	73	70	65	65
query56	280	289	283	283
query57	1459	1442	1346	1346
query58	284	256	259	256
query59	1616	1666	1414	1414
query60	297	266	254	254
query61	153	151	152	151
query62	694	643	591	591
query63	245	199	214	199
query64	2521	778	585	585
query65	4865	4798	4770	4770
query66	1836	498	392	392
query67	29268	29564	29471	29471
query68	3238	1586	1012	1012
query69	401	309	265	265
query70	1015	949	967	949
query71	352	341	305	305
query72	2836	2637	2370	2370
query73	806	788	440	440
query74	5145	4933	4765	4765
query75	2606	2596	2208	2208
query76	2327	1174	775	775
query77	351	382	288	288
query78	12465	12562	11968	11968
query79	1379	1179	782	782
query80	1285	541	455	455
query81	510	326	280	280
query82	621	160	121	121
query83	368	326	295	295
query84	268	161	129	129
query85	963	592	553	553
query86	427	302	293	293
query87	1836	1833	1788	1788
query88	3690	2798	2763	2763
query89	452	399	363	363
query90	2008	198	194	194
query91	204	196	171	171
query92	63	60	55	55
query93	1646	1634	999	999
query94	713	345	326	326
query95	804	564	495	495
query96	998	783	355	355
query97	2684	2688	2562	2562
query98	216	209	203	203
query99	1179	1162	1058	1058
Total cold run time: 259065 ms
Total hot run time: 174136 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 25.73 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit a7efbdf8e07f4dc60d62c9f91c612ac1f468e477, data reload: false

query1	0.01	0.01	0.01
query2	0.15	0.09	0.08
query3	0.37	0.24	0.24
query4	1.61	0.25	0.24
query5	0.33	0.32	0.32
query6	1.15	0.68	0.66
query7	0.05	0.01	0.01
query8	0.10	0.07	0.07
query9	0.51	0.40	0.38
query10	0.58	0.57	0.59
query11	0.33	0.19	0.18
query12	0.33	0.20	0.19
query13	0.52	0.52	0.52
query14	0.94	0.93	0.92
query15	0.68	0.59	0.60
query16	0.39	0.38	0.39
query17	0.97	1.00	1.07
query18	0.31	0.29	0.30
query19	1.89	1.84	1.75
query20	0.02	0.02	0.02
query21	15.38	0.37	0.30
query22	4.92	0.14	0.13
query23	15.84	0.50	0.30
query24	2.45	0.59	0.41
query25	0.15	0.10	0.10
query26	0.75	0.27	0.21
query27	0.10	0.11	0.10
query28	3.42	0.90	0.53
query29	12.45	4.41	3.50
query30	0.37	0.26	0.27
query31	2.78	0.61	0.33
query32	3.23	0.61	0.48
query33	3.02	2.96	3.04
query34	15.60	4.09	3.37
query35	3.23	3.26	3.24
query36	0.63	0.53	0.50
query37	0.12	0.09	0.08
query38	0.09	0.07	0.07
query39	0.07	0.06	0.06
query40	0.19	0.18	0.17
query41	0.13	0.09	0.09
query42	0.09	0.06	0.06
query43	0.07	0.06	0.07
Total cold run time: 96.32 s
Total hot run time: 25.73 s

### What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary: The cached remote file reader unit test reads back a fully cached block and leaves the opened cache file reader in the process-wide FDCache. Later FDCache-specific unit tests expect only their own entries to exist, so running the new test before those cases makes their cache size and eviction assertions fail. Clean the exact FDCache entry created by the cached remote file reader test when the test exits.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - ./run-be-ut.sh --run --filter=BlockFileCacheTest.cached_remote_file_reader_remote_only_on_miss:BlockFileCacheTest.fd_cache_remove:BlockFileCacheTest.fd_cache_evict
- Behavior changed: No
- Does this need documentation: No
@bobhan1

bobhan1 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 30137 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 4c097448a5cfaf24efd0050558d71cb492822d99, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17640	4151	4154	4151
q2	2107	323	213	213
q3	10320	1454	814	814
q4	4685	477	346	346
q5	7532	867	585	585
q6	188	181	141	141
q7	812	844	635	635
q8	9420	1582	1752	1582
q9	5662	4400	4442	4400
q10	6753	1808	1546	1546
q11	520	339	322	322
q12	726	559	463	463
q13	18229	3399	2831	2831
q14	270	284	248	248
q15	q16	795	792	717	717
q17	1008	930	996	930
q18	6978	5912	5683	5683
q19	1204	1266	1123	1123
q20	791	691	610	610
q21	5722	2780	2485	2485
q22	445	364	312	312
Total cold run time: 101807 ms
Total hot run time: 30137 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4532	4457	4409	4409
q2	287	322	216	216
q3	4677	5019	4409	4409
q4	2108	2225	1387	1387
q5	4498	4391	4366	4366
q6	238	181	130	130
q7	2291	1981	1746	1746
q8	2556	2318	2197	2197
q9	8344	7939	7920	7920
q10	4778	4761	4340	4340
q11	599	438	393	393
q12	794	788	548	548
q13	3297	3584	2933	2933
q14	302	314	277	277
q15	q16	726	731	653	653
q17	1410	1398	1510	1398
q18	7892	7509	7205	7205
q19	1202	1184	1110	1110
q20	2244	2221	1948	1948
q21	5362	4653	4595	4595
q22	537	493	418	418
Total cold run time: 58674 ms
Total hot run time: 52598 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 175443 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 4c097448a5cfaf24efd0050558d71cb492822d99, data reload: false

query5	4349	634	496	496
query6	487	217	221	217
query7	4876	593	336	336
query8	342	201	175	175
query9	8794	4138	4115	4115
query10	468	352	307	307
query11	5841	2345	2160	2160
query12	163	110	107	107
query13	1273	646	426	426
query14	6671	5494	5182	5182
query14_1	4502	4493	4464	4464
query15	234	205	187	187
query16	1052	530	462	462
query17	1185	751	597	597
query18	2761	490	350	350
query19	265	189	156	156
query20	157	111	113	111
query21	243	165	142	142
query22	13687	13580	13352	13352
query23	17589	16693	16244	16244
query23_1	16281	16369	16295	16295
query24	7471	1791	1282	1282
query24_1	1326	1320	1294	1294
query25	537	437	362	362
query26	1342	365	204	204
query27	2554	605	372	372
query28	4460	2022	2033	2022
query29	1073	584	483	483
query30	347	262	229	229
query31	1136	1112	999	999
query32	110	61	57	57
query33	523	324	250	250
query34	1230	1158	665	665
query35	814	791	702	702
query36	1408	1370	1239	1239
query37	156	108	92	92
query38	1912	1666	1677	1666
query39	929	915	916	915
query39_1	877	860	898	860
query40	248	163	140	140
query41	65	64	64	64
query42	96	92	93	92
query43	324	320	291	291
query44	1479	775	778	775
query45	210	196	178	178
query46	1077	1234	785	785
query47	2340	2342	2193	2193
query48	444	419	282	282
query49	584	437	330	330
query50	1091	428	369	369
query51	4455	4361	4406	4361
query52	89	87	75	75
query53	269	287	215	215
query54	294	244	229	229
query55	76	73	73	73
query56	326	313	296	296
query57	1429	1416	1300	1300
query58	311	281	260	260
query59	1628	1674	1498	1498
query60	320	283	249	249
query61	162	154	154	154
query62	703	642	589	589
query63	253	209	207	207
query64	2542	760	614	614
query65	4925	4809	4823	4809
query66	1825	518	384	384
query67	29861	29724	29606	29606
query68	3101	1636	952	952
query69	421	305	265	265
query70	1058	992	931	931
query71	361	315	309	309
query72	2926	2607	2417	2417
query73	840	766	427	427
query74	5144	5005	4813	4813
query75	2640	2608	2216	2216
query76	2374	1225	789	789
query77	359	390	288	288
query78	12326	12337	11847	11847
query79	1248	1230	783	783
query80	629	546	464	464
query81	451	338	283	283
query82	236	155	123	123
query83	343	319	289	289
query84	277	164	129	129
query85	991	606	515	515
query86	357	313	299	299
query87	1851	1831	1776	1776
query88	3730	2819	2783	2783
query89	423	414	371	371
query90	2234	202	200	200
query91	201	194	166	166
query92	67	62	58	58
query93	1484	1558	1029	1029
query94	569	362	320	320
query95	805	526	463	463
query96	1116	845	339	339
query97	2733	2695	2579	2579
query98	237	210	204	204
query99	1196	1144	1030	1030
Total cold run time: 260027 ms
Total hot run time: 175443 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 29.21 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 4c097448a5cfaf24efd0050558d71cb492822d99, data reload: false

query1	0.00	0.00	0.00
query2	0.11	0.05	0.06
query3	0.23	0.15	0.14
query4	1.04	0.13	0.12
query5	0.22	0.22	0.22
query6	1.13	1.00	1.36
query7	0.04	0.00	0.01
query8	0.06	0.03	0.04
query9	0.43	0.32	0.31
query10	0.54	0.54	0.56
query11	0.22	0.14	0.14
query12	0.19	0.15	0.15
query13	0.48	0.48	0.48
query14	1.03	1.02	1.00
query15	0.71	0.70	0.69
query16	0.33	0.32	0.32
query17	1.18	1.17	1.10
query18	0.24	0.21	0.21
query19	2.10	2.00	1.99
query20	0.02	0.01	0.01
query21	11.30	0.29	0.13
query22	3.31	0.05	0.05
query23	11.94	0.42	0.11
query24	1.91	0.42	0.18
query25	0.15	0.04	0.03
query26	0.62	0.25	0.16
query27	0.04	0.03	0.03
query28	2.67	1.15	0.63
query29	9.27	4.90	3.57
query30	0.30	0.16	0.15
query31	1.85	0.71	0.32
query32	3.26	0.62	0.50
query33	3.16	3.20	3.32
query34	11.33	5.86	5.42
query35	5.47	5.48	5.45
query36	0.62	0.46	0.42
query37	0.10	0.07	0.06
query38	0.06	0.04	0.04
query39	0.04	0.03	0.03
query40	0.19	0.16	0.15
query41	0.15	0.03	0.02
query42	0.04	0.03	0.03
query43	0.05	0.04	0.03
Total cold run time: 78.13 s
Total hot run time: 29.21 s

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 89.76% (368/410) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 74.57% (29622/39722)
Line Coverage 58.59% (324414/553740)
Region Coverage 55.26% (271679/491669)
Branch Coverage 56.58% (119683/211514)

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