Skip to content

[fix](stream) Fix stream scan partition prune state propagation - #65657

Merged
morrySnow merged 2 commits into
apache:masterfrom
yujun777:fix-stream-scan-partition-prune-loop
Jul 23, 2026
Merged

morrySnow merged 2 commits into
apache:masterfrom
yujun777:fix-stream-scan-partition-prune-loop

Conversation

@yujun777

@yujun777 yujun777 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Related Issue: close #65654

LogicalOlapTableStreamScan.withSelectedPartitionIds(List<Long>, boolean) diverged from LogicalOlapScan and changed the meaning of the second parameter. In LogicalOlapScan, the second parameter represents hasPartitionPredicate, while the rebuilt scan is always marked as partition-pruned. The stream scan override treated that second parameter as isPartitionPruned, which let partition pruning rebuild a stream scan that still looked unpruned and could be matched again by the same rewrite rule.

This PR keeps the stream-scan override consistent with LogicalOlapScan: the second parameter remains hasPartitionPredicate, and the rebuilt LogicalOlapTableStreamScan is marked as already partition-pruned.

@yujun777

Copy link
Copy Markdown
Contributor Author

run buildall

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

@yujun777 yujun777 changed the title [fix](fe) Fix stream scan partition prune state propagation [fix](stream) Fix stream scan partition prune state propagation Jul 15, 2026
@yujun777

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17715	4026	3986	3986
q2	2082	317	199	199
q3	10232	1356	786	786
q4	4675	469	339	339
q5	7627	843	585	585
q6	190	166	134	134
q7	758	804	606	606
q8	10006	1491	1550	1491
q9	5850	4289	4283	4283
q10	6811	1732	1461	1461
q11	494	332	301	301
q12	734	549	430	430
q13	18061	3253	2755	2755
q14	266	259	242	242
q15	q16	787	787	721	721
q17	996	901	1050	901
q18	7073	5867	5560	5560
q19	1536	1290	1028	1028
q20	749	647	555	555
q21	5893	2596	2273	2273
q22	433	349	300	300
Total cold run time: 102968 ms
Total hot run time: 28936 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4378	4263	4240	4240
q2	279	318	212	212
q3	4547	5000	4334	4334
q4	2031	2143	1560	1560
q5	4368	4266	4237	4237
q6	220	176	126	126
q7	1754	1885	1746	1746
q8	2538	2204	2147	2147
q9	7814	7765	7582	7582
q10	4691	4622	4175	4175
q11	567	418	395	395
q12	765	748	557	557
q13	3419	3544	2941	2941
q14	336	304	301	301
q15	q16	724	783	648	648
q17	1324	1297	1313	1297
q18	8035	7301	6986	6986
q19	1084	1033	1038	1033
q20	2192	2253	1940	1940
q21	5213	4563	4509	4509
q22	531	472	406	406
Total cold run time: 56810 ms
Total hot run time: 51372 ms

@hello-stephen

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

query5	4319	601	480	480
query6	460	216	205	205
query7	4854	596	364	364
query8	354	185	174	174
query9	8766	4135	4149	4135
query10	464	371	294	294
query11	5915	2315	2167	2167
query12	159	102	99	99
query13	1260	601	443	443
query14	6248	5285	4897	4897
query14_1	4271	4264	4259	4259
query15	214	205	177	177
query16	1031	475	439	439
query17	1117	717	577	577
query18	2451	489	351	351
query19	206	193	151	151
query20	117	110	108	108
query21	236	156	139	139
query22	13583	13545	13429	13429
query23	17300	16506	16189	16189
query23_1	16227	16202	16259	16202
query24	7845	1773	1274	1274
query24_1	1350	1284	1306	1284
query25	572	456	404	404
query26	1375	372	219	219
query27	2581	605	378	378
query28	4473	2019	2002	2002
query29	1101	621	501	501
query30	337	258	231	231
query31	1119	1098	978	978
query32	106	70	61	61
query33	529	317	266	266
query34	1188	1145	649	649
query35	784	816	667	667
query36	1191	1193	1080	1080
query37	156	109	93	93
query38	1892	1731	1640	1640
query39	903	907	856	856
query39_1	820	842	838	838
query40	246	166	144	144
query41	71	67	68	67
query42	94	94	95	94
query43	324	327	297	297
query44	1397	779	780	779
query45	197	191	173	173
query46	1107	1167	747	747
query47	2156	2129	2027	2027
query48	413	415	299	299
query49	587	447	346	346
query50	1043	404	328	328
query51	11005	10773	10511	10511
query52	96	90	77	77
query53	264	280	202	202
query54	314	244	226	226
query55	76	73	69	69
query56	301	298	303	298
query57	1302	1309	1218	1218
query58	294	270	259	259
query59	1566	1615	1440	1440
query60	373	265	245	245
query61	151	148	151	148
query62	536	496	431	431
query63	235	192	199	192
query64	2820	1042	856	856
query65	4734	4646	4659	4646
query66	1805	503	373	373
query67	29192	29239	29161	29161
query68	3301	1644	993	993
query69	405	294	260	260
query70	1062	966	931	931
query71	357	318	322	318
query72	3010	2652	2287	2287
query73	827	824	427	427
query74	5068	4934	4727	4727
query75	2496	2484	2132	2132
query76	2360	1186	759	759
query77	352	381	289	289
query78	11801	11971	11341	11341
query79	1520	1158	734	734
query80	1305	529	459	459
query81	552	322	280	280
query82	617	155	121	121
query83	370	310	285	285
query84	275	157	123	123
query85	963	636	499	499
query86	434	302	262	262
query87	1835	1826	1760	1760
query88	3697	2792	2768	2768
query89	452	387	327	327
query90	1906	207	192	192
query91	202	186	159	159
query92	67	60	60	60
query93	1720	1560	1018	1018
query94	717	360	323	323
query95	803	482	455	455
query96	1059	828	353	353
query97	2636	2615	2510	2510
query98	209	209	197	197
query99	1100	1109	988	988
Total cold run time: 264243 ms
Total hot run time: 177997 ms

@hello-stephen

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

query1	0.01	0.01	0.00
query2	0.09	0.05	0.05
query3	0.26	0.16	0.13
query4	1.68	0.14	0.14
query5	0.26	0.24	0.26
query6	1.41	1.09	1.14
query7	0.04	0.01	0.01
query8	0.05	0.04	0.04
query9	0.88	0.33	0.32
query10	0.59	0.57	0.57
query11	0.20	0.14	0.14
query12	0.18	0.15	0.16
query13	0.49	0.49	0.48
query14	1.06	1.03	1.04
query15	0.63	0.61	0.62
query16	0.36	0.36	0.34
query17	1.14	1.17	1.18
query18	0.25	0.22	0.22
query19	2.11	2.00	2.13
query20	0.02	0.01	0.01
query21	15.41	0.24	0.13
query22	4.63	0.05	0.05
query23	16.18	0.30	0.12
query24	2.94	0.46	0.35
query25	0.11	0.05	0.04
query26	0.73	0.22	0.15
query27	0.03	0.04	0.03
query28	3.54	0.95	0.57
query29	12.47	4.10	3.27
query30	0.27	0.16	0.15
query31	2.77	0.60	0.31
query32	3.22	0.61	0.49
query33	3.31	3.14	3.22
query34	15.49	4.22	3.50
query35	3.55	3.54	3.55
query36	0.56	0.43	0.44
query37	0.09	0.07	0.06
query38	0.05	0.04	0.04
query39	0.04	0.03	0.03
query40	0.17	0.17	0.14
query41	0.08	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.03	0.04
Total cold run time: 97.43 s
Total hot run time: 25.37 s

@morrySnow

Copy link
Copy Markdown
Contributor

/review

morrySnow
morrySnow previously approved these changes Jul 15, 2026
@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Jul 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

PR approved by anyone and no changes requested.

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

Found one blocking issue in the stream scan partition-prune state propagation fix.

The changed override now matches the base LogicalOlapScan contract locally, but the corrected hasPartitionPredicate=false state is not preserved through stream normalization. Normalized base/binlog scans can still be reclassified as having manual partition predicates, which affects SQL block-rule enforcement for partitioned stream queries without an effective partition filter.

Review scope and checkpoints: inspected the single changed file plus partition pruning, stream normalization, physical translation, SQL block-rule enforcement, wrapper scan metadata, one-argument selected-partition callers, and existing FE/regression coverage. No concurrency, lifecycle, config, persistence, storage-format, FE-BE protocol, data-write, or transaction-path change was introduced by this PR. User focus file had no additional focus. Validation was static only; this review-only runner is missing thirdparty/installed/bin/protoc, so I did not run FE tests or builds.

@yujun777
yujun777 force-pushed the fix-stream-scan-partition-prune-loop branch from f9b4ea9 to 72b7474 Compare July 16, 2026 06:21
@yujun777

Copy link
Copy Markdown
Contributor Author

run buildall

@github-actions github-actions Bot removed the approved Indicates a PR has been approved by one committer. label Jul 16, 2026
@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17682	4065	3975	3975
q2	2033	329	195	195
q3	10250	1416	857	857
q4	4707	468	337	337
q5	7609	855	569	569
q6	199	171	140	140
q7	746	815	628	628
q8	10192	1580	1606	1580
q9	5953	4317	4337	4317
q10	6845	1734	1435	1435
q11	506	350	334	334
q12	750	569	450	450
q13	18118	3288	2787	2787
q14	269	265	246	246
q15	q16	786	784	711	711
q17	1025	1118	955	955
q18	6974	5724	5482	5482
q19	1253	1305	1007	1007
q20	796	676	588	588
q21	5719	2658	2389	2389
q22	424	353	289	289
Total cold run time: 102836 ms
Total hot run time: 29271 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4421	4298	4320	4298
q2	285	317	209	209
q3	4544	4947	4410	4410
q4	2059	2130	1369	1369
q5	4354	4263	4314	4263
q6	232	177	126	126
q7	1755	2079	1752	1752
q8	2526	2154	2088	2088
q9	7936	7838	7877	7838
q10	4644	4643	4182	4182
q11	554	415	390	390
q12	736	763	595	595
q13	3406	3563	2934	2934
q14	306	326	304	304
q15	q16	716	739	657	657
q17	1369	1322	1333	1322
q18	7949	7260	6856	6856
q19	1078	1059	1099	1059
q20	2212	2179	1937	1937
q21	5200	4507	4377	4377
q22	520	447	401	401
Total cold run time: 56802 ms
Total hot run time: 51367 ms

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17675	4177	4126	4126
q2	2050	329	199	199
q3	10276	1454	840	840
q4	4686	471	343	343
q5	7491	862	572	572
q6	189	179	140	140
q7	787	833	616	616
q8	9359	1706	1628	1628
q9	6089	4424	4352	4352
q10	6814	1733	1512	1512
q11	521	357	332	332
q12	751	588	467	467
q13	18111	3394	2743	2743
q14	264	266	246	246
q15	q16	792	772	701	701
q17	984	948	994	948
q18	7113	5885	5594	5594
q19	1310	1251	1055	1055
q20	792	725	584	584
q21	6094	2688	2483	2483
q22	430	356	305	305
Total cold run time: 102578 ms
Total hot run time: 29786 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4497	4427	4387	4387
q2	312	318	212	212
q3	4587	4986	4444	4444
q4	2121	2162	1380	1380
q5	4447	4341	4311	4311
q6	238	177	130	130
q7	2201	1989	1669	1669
q8	2644	2194	2367	2194
q9	8053	8273	7855	7855
q10	4661	4675	4207	4207
q11	615	421	384	384
q12	765	761	551	551
q13	3368	3673	2892	2892
q14	284	326	279	279
q15	q16	714	717	644	644
q17	1373	1350	1378	1350
q18	8052	7459	7312	7312
q19	1185	1175	1109	1109
q20	2265	2214	1949	1949
q21	5299	4642	4530	4530
q22	550	465	402	402
Total cold run time: 58231 ms
Total hot run time: 52191 ms

@hello-stephen

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

query5	4312	647	511	511
query6	471	241	207	207
query7	4898	618	342	342
query8	349	190	175	175
query9	8786	4112	4117	4112
query10	508	353	304	304
query11	5923	2368	2151	2151
query12	163	105	110	105
query13	1264	628	432	432
query14	6232	5308	4990	4990
query14_1	4319	4339	4362	4339
query15	214	206	183	183
query16	1032	478	474	474
query17	963	731	586	586
query18	2444	498	358	358
query19	213	200	153	153
query20	110	110	108	108
query21	232	165	142	142
query22	13666	13640	13443	13443
query23	17434	16868	16148	16148
query23_1	16278	16250	16195	16195
query24	7592	1814	1288	1288
query24_1	1333	1282	1299	1282
query25	585	485	408	408
query26	1383	360	210	210
query27	2597	618	383	383
query28	4516	2008	2003	2003
query29	1066	624	474	474
query30	345	251	228	228
query31	1113	1084	971	971
query32	110	66	60	60
query33	505	309	243	243
query34	1198	1155	659	659
query35	782	777	674	674
query36	1220	1182	1035	1035
query37	154	108	92	92
query38	1889	1706	1655	1655
query39	880	887	852	852
query39_1	818	830	863	830
query40	248	170	145	145
query41	68	66	63	63
query42	93	92	94	92
query43	333	348	295	295
query44	1495	774	762	762
query45	199	181	171	171
query46	1063	1202	726	726
query47	2068	2050	2008	2008
query48	423	437	286	286
query49	574	411	320	320
query50	1104	431	337	337
query51	10634	10426	10754	10426
query52	85	87	80	80
query53	270	282	201	201
query54	301	258	228	228
query55	74	71	64	64
query56	310	323	296	296
query57	1316	1291	1183	1183
query58	289	262	268	262
query59	1613	1683	1483	1483
query60	311	276	256	256
query61	150	149	145	145
query62	541	496	434	434
query63	239	204	213	204
query64	2826	1019	851	851
query65	4727	4627	4644	4627
query66	1852	497	374	374
query67	29306	29253	29133	29133
query68	3146	1545	986	986
query69	404	298	270	270
query70	1059	966	960	960
query71	378	352	320	320
query72	3117	2750	2359	2359
query73	854	807	435	435
query74	5081	4934	4738	4738
query75	2553	2518	2135	2135
query76	2342	1224	812	812
query77	361	387	283	283
query78	11846	11753	11214	11214
query79	1410	1140	752	752
query80	671	546	452	452
query81	454	334	300	300
query82	576	159	119	119
query83	408	341	299	299
query84	336	165	133	133
query85	965	630	506	506
query86	377	325	281	281
query87	1814	1818	1767	1767
query88	3753	2789	2780	2780
query89	456	381	360	360
query90	1882	203	196	196
query91	202	188	170	170
query92	64	60	58	58
query93	1597	1571	1039	1039
query94	536	360	312	312
query95	800	586	479	479
query96	1092	787	349	349
query97	2642	2621	2480	2480
query98	215	213	199	199
query99	1101	1124	969	969
Total cold run time: 263323 ms
Total hot run time: 178294 ms

@hello-stephen

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

query1	0.01	0.01	0.01
query2	0.10	0.05	0.05
query3	0.29	0.14	0.13
query4	1.61	0.13	0.14
query5	0.24	0.23	0.22
query6	1.25	1.05	1.07
query7	0.04	0.01	0.00
query8	0.06	0.04	0.04
query9	0.40	0.33	0.30
query10	0.56	0.58	0.60
query11	0.19	0.13	0.13
query12	0.17	0.15	0.14
query13	0.48	0.47	0.47
query14	1.02	1.01	1.01
query15	0.62	0.60	0.59
query16	0.32	0.32	0.34
query17	1.14	1.11	1.11
query18	0.23	0.21	0.21
query19	2.08	1.91	1.94
query20	0.02	0.01	0.00
query21	15.43	0.22	0.13
query22	4.92	0.06	0.05
query23	16.16	0.31	0.12
query24	2.97	0.44	0.36
query25	0.12	0.05	0.05
query26	0.72	0.20	0.16
query27	0.05	0.03	0.04
query28	3.52	0.90	0.56
query29	12.50	4.16	3.29
query30	0.28	0.15	0.15
query31	2.78	0.59	0.31
query32	3.21	0.59	0.49
query33	3.29	3.24	3.18
query34	15.63	4.20	3.51
query35	3.59	3.52	3.51
query36	0.56	0.42	0.44
query37	0.09	0.07	0.06
query38	0.06	0.04	0.04
query39	0.04	0.03	0.03
query40	0.17	0.16	0.15
query41	0.08	0.03	0.02
query42	0.04	0.03	0.03
query43	0.04	0.03	0.03
Total cold run time: 97.08 s
Total hot run time: 25.08 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100% (0/0) 🎉
Increment coverage report
Complete coverage report

@morrySnow

Copy link
Copy Markdown
Contributor

/review

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

Copy link
Copy Markdown
Contributor

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

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

Request changes: the existing partition-filter propagation blocker remains unresolved at head 72b7474d41f01a654d940c6737b51a43d6fa12f8.

The local builder change is correct: it aligns LogicalOlapTableStreamScan.withSelectedPartitionIds(List<Long>, boolean) with the parent contract, marks both boolean paths as already pruned, and stops the repeated PruneOlapScanPartition rewrite. However, NormalizeOlapTableStreamScan still lowers the stream into fresh base/binlog scans by putting internally selected partition IDs into specifiedPartitions. Recursive top-down pruning then classifies those IDs as a manual partition filter and sets every executable child of a partitioned stream to hasPartitionPredicate=true. An unfiltered partitioned stream query can therefore still bypass a SQL block rule with require_partition_filter=true. This is the same blocker already anchored in the existing inline thread, which GitHub currently marks resolved even though the code path remains; I did not add a duplicate inline comment.

Critical checkpoint conclusions:

  • Goal and correctness: the optimizer-loop root cause is fixed locally, but downstream execution semantics remain incorrect because the partition-filter flag is not preserved through normalization.
  • Scope and clarity: the two-file patch is small and the production change follows the parent builder contract.
  • Parallel paths: incremental, snapshot, and reset lowering all create affected base/binlog scans; both filtered and unfiltered paths were traced through logical implementation, physical translation, StmtExecutor, and SqlBlockRuleMgr.
  • Test coverage and results: the new JUnit test deterministically catches the old direct false-value builder behavior, but it stops after analysis and does not exercise the real rewrite loop, the true-value path, normalization, partial empty-partition pruning, final OlapScanNode state, or block-rule enforcement. Current PR checks report FE UT, compile, CheckStyle, and regression jobs passing, but they do not disprove these uncovered state transitions. No local build or test was run because this is a review-only runner and the local third-party/protoc dependencies are absent.
  • Performance: the change removes the unbounded rewrite/allocation loop and adds no hot-path overhead.
  • Concurrency, lifecycle, configuration, persistence, transaction/data-write, storage compatibility, FE-BE protocol, memory safety, and observability: not involved in this patch; no issue found for these checkpoints.
  • User focus: no additional focus was provided; the full PR and its downstream partition-filter behavior were reviewed.

Please preserve the already-computed hasPartitionPredicate value through both partial empty-partition selection and normalized-child construction. Add end-to-end filtered/unfiltered assertions, including a filtered case where only some selected partitions are empty, before merging.

yujun777 added 2 commits July 22, 2026 14:42
### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: Incremental IVM refresh on table stream scans could loop forever during partition pruning. The root cause was `LogicalOlapTableStreamScan.withSelectedPartitionIds(List<Long>, boolean)` redefining the second argument as `isPartitionPruned`, while callers and the parent `LogicalOlapScan` contract treat it as `hasPartitionPredicate`. When `PruneOlapScanPartition` passed `false` for a scan without a partition predicate, the stream scan builder also reset `partitionPruned` to `false`, so the rewrite kept matching the same scan and rebuilding the plan. This caused MTMV tasks such as `mv_ivm_partition_key` incremental refresh to stay running and continuously allocate plans. The fix aligns the stream scan override with the parent contract: the boolean argument now represents `hasPartitionPredicate`, and scans rebuilt through this path are always marked as partition-pruned.

### Release note

None

### Check List (For Author)

- Test: Manual test
    - Verified `test_ivm_partition_unique_key` with local regression run: `./run-regression-test.sh --run -d mtmv_p0 -s test_ivm_partition_unique_key`
- Behavior changed: Yes (fixes incremental IVM refresh from hanging during stream scan partition pruning)
- Does this need documentation: No
Add a focused FE UT for LogicalOlapTableStreamScan.withSelectedPartitionIds
so the partition-pruned state propagation is covered directly.

Key changes:
- add a stream scan UT that verifies withSelectedPartitionIds marks partitionPruned
- assert hasPartitionPredicate is preserved when pruning state is updated
- add a helper to find the first LogicalOlapTableStreamScan from the analyzed plan

Unit Test:
- run-fe-ut.sh --run org.apache.doris.nereids.trees.plans.ExplainTableStreamPlanTest
@yujun777
yujun777 force-pushed the fix-stream-scan-partition-prune-loop branch from 72b7474 to d2bc4f6 Compare July 22, 2026 06:42
@yujun777

Copy link
Copy Markdown
Contributor Author

run buildall

@yujun777

Copy link
Copy Markdown
Contributor Author

Request changes: the existing partition-filter propagation blocker remains unresolved at head 72b7474d41f01a654d940c6737b51a43d6fa12f8.

The local builder change is correct: it aligns LogicalOlapTableStreamScan.withSelectedPartitionIds(List<Long>, boolean) with the parent contract, marks both boolean paths as already pruned, and stops the repeated PruneOlapScanPartition rewrite. However, NormalizeOlapTableStreamScan still lowers the stream into fresh base/binlog scans by putting internally selected partition IDs into specifiedPartitions. Recursive top-down pruning then classifies those IDs as a manual partition filter and sets every executable child of a partitioned stream to hasPartitionPredicate=true. An unfiltered partitioned stream query can therefore still bypass a SQL block rule with require_partition_filter=true. This is the same blocker already anchored in the existing inline thread, which GitHub currently marks resolved even though the code path remains; I did not add a duplicate inline comment.

Critical checkpoint conclusions:

  • Goal and correctness: the optimizer-loop root cause is fixed locally, but downstream execution semantics remain incorrect because the partition-filter flag is not preserved through normalization.
  • Scope and clarity: the two-file patch is small and the production change follows the parent builder contract.
  • Parallel paths: incremental, snapshot, and reset lowering all create affected base/binlog scans; both filtered and unfiltered paths were traced through logical implementation, physical translation, StmtExecutor, and SqlBlockRuleMgr.
  • Test coverage and results: the new JUnit test deterministically catches the old direct false-value builder behavior, but it stops after analysis and does not exercise the real rewrite loop, the true-value path, normalization, partial empty-partition pruning, final OlapScanNode state, or block-rule enforcement. Current PR checks report FE UT, compile, CheckStyle, and regression jobs passing, but they do not disprove these uncovered state transitions. No local build or test was run because this is a review-only runner and the local third-party/protoc dependencies are absent.
  • Performance: the change removes the unbounded rewrite/allocation loop and adds no hot-path overhead.
  • Concurrency, lifecycle, configuration, persistence, transaction/data-write, storage compatibility, FE-BE protocol, memory safety, and observability: not involved in this patch; no issue found for these checkpoints.
  • User focus: no additional focus was provided; the full PR and its downstream partition-filter behavior were reviewed.

Please preserve the already-computed hasPartitionPredicate value through both partial empty-partition selection and normalized-child construction. Add end-to-end filtered/unfiltered assertions, including a filtered case where only some selected partitions are empty, before merging.

The requested changes are outside the scope of this PR.

This patch only fixes the partition-pruned state propagation and aligns LogicalOlapTableStreamScan.withSelectedPartitionIds() with the
parent contract, eliminating the repeated PruneOlapScanPartition rewrite.

NormalizeOlapTableStreamScan lowering streams into executable base/binlog LogicalOlapScan children with internally selected
partitions is existing behavior and is unchanged by this PR. Whether those internal selections should have different
require_partition_filter semantics is a separate issue that needs an end-to-end reproduction and a dedicated PR; it should not block
this state-propagation fix.

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17643	4059	4085	4059
q2	2028	322	201	201
q3	10279	1439	834	834
q4	4684	476	339	339
q5	7547	867	593	593
q6	180	176	142	142
q7	734	833	628	628
q8	9315	1561	1614	1561
q9	5552	4337	4360	4337
q10	6765	1734	1461	1461
q11	513	361	347	347
q12	739	575	450	450
q13	18103	3351	2752	2752
q14	282	265	241	241
q15	q16	797	774	714	714
q17	1047	1011	1068	1011
q18	7000	5868	5575	5575
q19	1293	1341	1037	1037
q20	897	685	639	639
q21	6023	2664	2478	2478
q22	445	360	305	305
Total cold run time: 101866 ms
Total hot run time: 29704 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4446	4387	4479	4387
q2	301	328	219	219
q3	4647	4992	4381	4381
q4	2101	2176	1371	1371
q5	4436	4381	4335	4335
q6	242	185	133	133
q7	1755	2311	1775	1775
q8	2637	2241	2236	2236
q9	8066	8226	7993	7993
q10	4726	4660	4272	4272
q11	573	412	378	378
q12	780	789	546	546
q13	3319	3665	2924	2924
q14	306	309	278	278
q15	q16	692	752	658	658
q17	1359	1345	1503	1345
q18	7857	7499	7322	7322
q19	1176	1082	1072	1072
q20	2220	2212	1970	1970
q21	5344	4675	4444	4444
q22	529	457	446	446
Total cold run time: 57512 ms
Total hot run time: 52485 ms

@hello-stephen

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

query5	4340	640	494	494
query6	467	225	207	207
query7	4873	648	363	363
query8	338	195	178	178
query9	8773	4117	4122	4117
query10	478	376	315	315
query11	5876	2385	2146	2146
query12	161	103	105	103
query13	1264	617	433	433
query14	6268	5269	4924	4924
query14_1	4302	4268	4310	4268
query15	212	205	184	184
query16	1015	485	500	485
query17	963	732	582	582
query18	2442	478	350	350
query19	215	196	147	147
query20	110	108	107	107
query21	235	162	139	139
query22	13670	13538	13431	13431
query23	17357	16582	16176	16176
query23_1	16190	16286	16210	16210
query24	7625	1774	1283	1283
query24_1	1284	1284	1274	1274
query25	582	465	395	395
query26	1334	367	219	219
query27	2577	579	382	382
query28	4505	1990	1968	1968
query29	1092	640	501	501
query30	353	268	228	228
query31	1132	1115	998	998
query32	107	67	62	62
query33	540	328	268	268
query34	1159	1182	635	635
query35	768	775	676	676
query36	1170	1191	1029	1029
query37	158	123	94	94
query38	1868	1753	1670	1670
query39	876	884	853	853
query39_1	853	854	843	843
query40	259	167	155	155
query41	66	62	65	62
query42	93	91	90	90
query43	340	333	279	279
query44	1476	773	771	771
query45	190	188	174	174
query46	1103	1185	746	746
query47	2104	2076	1968	1968
query48	414	394	287	287
query49	588	455	313	313
query50	1083	437	333	333
query51	10752	10800	10765	10765
query52	87	87	77	77
query53	269	286	203	203
query54	280	228	225	225
query55	75	72	68	68
query56	307	306	287	287
query57	1305	1318	1173	1173
query58	284	269	258	258
query59	1608	1693	1422	1422
query60	329	275	255	255
query61	155	151	148	148
query62	536	496	436	436
query63	243	202	205	202
query64	2815	1037	865	865
query65	4711	4602	4617	4602
query66	1839	499	385	385
query67	29363	28677	29073	28677
query68	3077	1491	942	942
query69	401	299	273	273
query70	1087	948	969	948
query71	393	348	302	302
query72	3091	2739	2384	2384
query73	789	848	462	462
query74	5040	4908	4726	4726
query75	2559	2512	2160	2160
query76	2329	1224	798	798
query77	361	378	293	293
query78	11905	11951	11345	11345
query79	1366	1134	723	723
query80	1276	602	472	472
query81	500	326	287	287
query82	560	163	121	121
query83	373	339	314	314
query84	332	159	131	131
query85	981	619	524	524
query86	411	293	284	284
query87	1838	1829	1767	1767
query88	3757	2813	2776	2776
query89	449	391	323	323
query90	1813	206	203	203
query91	203	194	164	164
query92	63	61	59	59
query93	1690	1574	1000	1000
query94	685	358	335	335
query95	793	570	466	466
query96	1049	757	370	370
query97	2608	2609	2498	2498
query98	211	211	208	208
query99	1088	1107	972	972
Total cold run time: 263505 ms
Total hot run time: 177932 ms

@hello-stephen

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

query1	0.00	0.00	0.00
query2	0.09	0.07	0.04
query3	0.25	0.14	0.13
query4	1.60	0.13	0.14
query5	0.24	0.23	0.23
query6	1.25	1.07	1.08
query7	0.03	0.01	0.00
query8	0.05	0.03	0.04
query9	0.40	0.31	0.32
query10	0.56	0.55	0.53
query11	0.20	0.15	0.14
query12	0.19	0.15	0.14
query13	0.50	0.47	0.48
query14	1.02	1.03	1.02
query15	0.62	0.59	0.61
query16	0.31	0.34	0.32
query17	1.07	1.12	1.11
query18	0.23	0.22	0.21
query19	1.96	1.91	1.94
query20	0.01	0.02	0.01
query21	15.44	0.23	0.13
query22	4.77	0.05	0.06
query23	16.13	0.31	0.12
query24	3.06	0.46	0.32
query25	0.11	0.06	0.05
query26	0.74	0.22	0.16
query27	0.04	0.04	0.04
query28	3.51	0.95	0.53
query29	12.48	4.09	3.30
query30	0.27	0.16	0.16
query31	2.77	0.60	0.32
query32	3.24	0.59	0.49
query33	3.14	3.27	3.15
query34	15.41	4.23	3.49
query35	3.51	3.49	3.50
query36	0.55	0.42	0.42
query37	0.09	0.06	0.06
query38	0.06	0.04	0.04
query39	0.04	0.03	0.03
query40	0.18	0.17	0.16
query41	0.08	0.03	0.03
query42	0.03	0.03	0.04
query43	0.04	0.04	0.04
Total cold run time: 96.27 s
Total hot run time: 25 s

@morrySnow

Copy link
Copy Markdown
Contributor

/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 complete for head d2bc4f6e23518bd80e9338c923aef3448d9cd107. I found no new patch-scoped blocking issue, and this focused builder-contract fix is acceptable.

Critical checkpoint conclusions:

  • Goal and correctness: the override now matches LogicalOlapScan.withSelectedPartitionIds(List<Long>, boolean): the boolean is hasPartitionPredicate, while the rebuilt scan is always marked partitionPruned=true. The only production two-argument caller computes that predicate flag before dynamic dispatch, and the corrected postcondition removes the stream scan from the next PruneOlapScanPartition match, terminating the reported rewrite loop.
  • Scope and clarity: the production change is minimal and copies the remaining scan state unchanged, including partition-prunable predicates, scan parameters, selected tablets/index, preaggregation state, slots, alias, and stream read mode.
  • Parallel and conditional paths: I traced both overloads through PruneOlapScanPartition, PruneEmptyPartition, MV visitors, stream normalization, logical-to-physical conversion, OlapScanNode, and SQL block-rule checking. The one-argument predicate-state and normalized-child concerns are already fully covered by the existing inline discussion, so I did not submit a duplicate.
  • Test coverage and results: the added JUnit 5 test deterministically checks the corrected local false-value builder contract. It does not execute the real top-down rewrite/normalization path; that exact coverage limitation, including true-predicate and partially-empty cases, is already recorded in the existing thread. This review runner is restricted to review operations, so I ran no build or test and am not claiming local execution results.
  • Concurrency and lifecycle: no threads, shared mutable state, locks, static initialization, or resource-lifecycle changes are introduced.
  • Configuration, compatibility, and FE/BE contracts: no configuration, persisted format, RPC/thrift field, function symbol, or rolling-upgrade behavior changes.
  • Error handling and observability: no new error path, exception boundary, log, or metric is needed for this immutable plan-builder correction.
  • Transactions, persistence, and data writes: not involved; there is no EditLog, transaction-state, visibility-version, or data-write change.
  • Performance: the fix prevents repeated optimizer rewrites and associated CPU/allocation growth, with no new hot-path work.
  • Test result artifacts: no regression .out file is involved in this FE unit-test-only change.
  • User focus: no additional focus was provided; the full two-file patch and its upstream/downstream planner paths were reviewed.

Review convergence completed in one round: two full-review lanes and a separate risk-focused lane all returned NO_NEW_VALUABLE_FINDINGS, and the final changed-file/candidate sweep found no unresolved point or new inline comment.

@morrySnow
morrySnow merged commit 07bd92a into apache:master Jul 23, 2026
35 of 36 checks passed
0AyanamiRei pushed a commit to 0AyanamiRei/doris that referenced this pull request Jul 27, 2026
…he#65657)

### What problem does this PR solve?

Related Issue: close apache#65654

`LogicalOlapTableStreamScan.withSelectedPartitionIds(List<Long>,
boolean)` diverged from `LogicalOlapScan` and changed the meaning of the
second parameter. In `LogicalOlapScan`, the second parameter represents
`hasPartitionPredicate`, while the rebuilt scan is always marked as
partition-pruned. The stream scan override treated that second parameter
as `isPartitionPruned`, which let partition pruning rebuild a stream
scan that still looked unpruned and could be matched again by the same
rewrite rule.

This PR keeps the stream-scan override consistent with
`LogicalOlapScan`: the second parameter remains `hasPartitionPredicate`,
and the rebuilt `LogicalOlapTableStreamScan` is marked as already
partition-pruned.
wyxxxcat pushed a commit to wyxxxcat/doris that referenced this pull request Aug 17, 2026
…he#65657)

### What problem does this PR solve?

Related Issue: close apache#65654

`LogicalOlapTableStreamScan.withSelectedPartitionIds(List<Long>,
boolean)` diverged from `LogicalOlapScan` and changed the meaning of the
second parameter. In `LogicalOlapScan`, the second parameter represents
`hasPartitionPredicate`, while the rebuilt scan is always marked as
partition-pruned. The stream scan override treated that second parameter
as `isPartitionPruned`, which let partition pruning rebuild a stream
scan that still looked unpruned and could be matched again by the same
rewrite rule.

This PR keeps the stream-scan override consistent with
`LogicalOlapScan`: the second parameter remains `hasPartitionPredicate`,
and the rebuilt `LogicalOlapTableStreamScan` is marked as already
partition-pruned.
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. binlog reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] LogicalOlapTableStreamScan can loop forever after partition pruning

3 participants