Skip to content

[improvement](fe) TopN lazy materialization support struct/variant nested column pruning#63736

Open
englefly wants to merge 31 commits into
apache:masterfrom
englefly:lazy-mat-nest
Open

[improvement](fe) TopN lazy materialization support struct/variant nested column pruning#63736
englefly wants to merge 31 commits into
apache:masterfrom
englefly:lazy-mat-nest

Conversation

@englefly
Copy link
Copy Markdown
Contributor

@englefly englefly commented May 27, 2026

Extend TopN lazy materialization to defer reading complex-type base columns
(struct, variant, map, array) until after TopN filtering, and expand the
scope to all non-trivial projection expressions.

Core Changes

PullUpProjectExprUnderTopN (new CustomRewriter):

  • Two-pass design: Collector walks the plan tree top-down to find qualifying
    TopNs, then walks into descendants (through Join/Filter) to find Projects
    with pull-able expressions. Replacer simplifies found Projects bottom-up
    and adds upper Projects to restore pulled-up expressions.
  • Eligible expressions: Alias with non-trivial child (not Slot/Literal),
    not referenced by TopN order keys, no NoneMovableFunction.
  • Excludes: CTE Producers (output mapping safety), Join/Filter conditions
    that reference pulled-up outputs (cleared/removed).

LazyMaterializeTopN (simplified):

  • Expression pull-up moved from physical PlanPostProcessor to logical
    CustomRewriter, eliminating hard-coded MERGE_SORT→Distribute→LOCAL_SORT→Project
    shape walking. Now only handles MaterializeNode insertion.

OperativeColumnDerive:

  • Skip PreferPushDownProject input slots from operative propagation so
    complex-type base columns can be lazy.

Other:

  • PhysicalLazyMaterialize: propagate access paths to lazy output slots
    for nested column/subPath pruning on BE.
  • MaterializationNode/PlanNode: fix nested column display in EXPLAIN.
  • NoneMovableFunction: fix missing interface name.
  • Session variable enable_topn_expr_pullup for rollback.

Tests:

  • topn_expr_pullup: 15 test cases covering struct/variant/map/array, non-PPD
    expressions, joins, column order preservation, negative cases.
  • topn_lazy_nested_column_pruning: 17 test cases for struct/variant nested
    pruning + map/array lazy mat + multi-level variant nesting.
  • Updated 48 shape_check .out files to reflect new plan shapes.

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • 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

…sted column pruning

Core changes:
- LazyMaterializeTopN: find projects below TopN with PreferPushDownProject
  or variant subColPath expressions, simplify them to expose base columns
  as lazy candidates. Pull up expressions above Materialize for lazy mat.
- LazySlotPruning: extract shouldPruneChild() for safe override when
  logical properties are stale after plan restructuring
- OperativeColumnDerive: skip PreferPushDownProject input slots from
  operative propagation so struct/variant columns can be lazy
- PhysicalLazyMaterialize: propagate access paths to lazy output slots
- MaterializationNode: use materializeTupleDescriptor for nested column
  info display (was outputTupleDesc, never set)
- PlanNode: add subColLables to printNestedColumns for variant

Tests cover struct (struct_element + pruned type) and variant
(element_at + sub path) lazy materialization with nested column pruning.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@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?

@englefly
Copy link
Copy Markdown
Contributor Author

/review

@englefly
Copy link
Copy Markdown
Contributor Author

run buildall

@englefly
Copy link
Copy Markdown
Contributor Author

run buildall

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.

I found one blocking correctness issue that should be fixed before merge.

Critical checkpoint conclusions:

  • Goal/test coverage: The PR aims to enable TopN lazy materialization for nested/PPD expressions. It adds regression coverage for several id, nested_expr shapes, but misses output-order permutations where the pulled-up expression appears before other selected columns.
  • Scope/focus: The feature is generally focused, but the final TopN projection reconstruction changes user-visible column order in the new pulled-up expression path.
  • Concurrency/lifecycle: No new shared mutable concurrency or non-obvious lifecycle issue found in the reviewed FE paths.
  • Config/compatibility: No new config or incompatible storage/protocol format change found.
  • Parallel paths: Normal and using_index TopN lazy materialization cases were reviewed; the reported issue is specific to the new nested/PPD pull-up path.
  • Special checks/error handling: No ignored Status or FE exception-boundary issue found in the actual PR diff.
  • Tests/results: Regression tests are deterministic, but they do not cover pulled-up nested expressions in non-tail output positions.
  • Observability/performance/transactions: No additional observability, performance, transaction, or persistence blocker found for this PR.

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

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 32544 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 4897f0cfc299fd90b64a17d6658e5891a6bbc55b, 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	17656	4380	4235	4235
q2	q3	10791	1465	811	811
q4	4692	481	346	346
q5	7606	2333	2216	2216
q6	239	184	141	141
q7	974	811	636	636
q8	9396	1778	1792	1778
q9	5560	5082	5052	5052
q10	6424	2199	1905	1905
q11	445	276	256	256
q12	698	437	312	312
q13	18165	3446	2782	2782
q14	273	261	244	244
q15	q16	831	775	709	709
q17	1023	1031	1048	1031
q18	7032	5897	5483	5483
q19	1182	1495	1114	1114
q20	595	451	274	274
q21	6049	3012	2891	2891
q22	454	387	328	328
Total cold run time: 100085 ms
Total hot run time: 32544 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	4974	4889	5177	4889
q2	q3	5013	5253	4648	4648
q4	2284	2309	1487	1487
q5	5106	4828	4736	4736
q6	249	189	135	135
q7	1914	1774	1642	1642
q8	2621	2422	2303	2303
q9	7889	7506	7453	7453
q10	4762	4722	4207	4207
q11	576	431	387	387
q12	750	755	550	550
q13	3063	3419	2815	2815
q14	271	276	260	260
q15	q16	703	704	617	617
q17	1334	1307	1300	1300
q18	7331	7142	6830	6830
q19	1133	1147	1151	1147
q20	2234	2230	1963	1963
q21	5432	4820	4730	4730
q22	528	475	422	422
Total cold run time: 58167 ms
Total hot run time: 52521 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 172873 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 4897f0cfc299fd90b64a17d6658e5891a6bbc55b, data reload: false

query5	4319	661	547	547
query6	338	233	199	199
query7	4305	539	317	317
query8	334	269	221	221
query9	8791	4119	4096	4096
query10	474	349	299	299
query11	5826	2537	2304	2304
query12	191	131	124	124
query13	1273	597	462	462
query14	6141	5511	5259	5259
query14_1	4571	4539	4581	4539
query15	219	215	186	186
query16	1034	469	442	442
query17	1155	760	637	637
query18	2701	500	377	377
query19	227	213	175	175
query20	145	137	135	135
query21	219	143	124	124
query22	13670	13655	13325	13325
query23	17531	16437	16206	16206
query23_1	16308	16462	16496	16462
query24	7426	1771	1371	1371
query24_1	1320	1350	1341	1341
query25	573	506	454	454
query26	1310	331	178	178
query27	2663	585	345	345
query28	4436	2059	2051	2051
query29	1013	662	515	515
query30	307	247	213	213
query31	1134	1079	955	955
query32	96	79	76	76
query33	557	357	336	336
query34	1241	1146	651	651
query35	785	783	715	715
query36	1396	1375	1224	1224
query37	154	108	90	90
query38	3217	3169	3096	3096
query39	934	923	902	902
query39_1	878	886	876	876
query40	228	146	125	125
query41	65	64	62	62
query42	114	116	108	108
query43	342	334	296	296
query44	
query45	209	209	199	199
query46	1071	1210	742	742
query47	2367	2333	2213	2213
query48	383	425	295	295
query49	638	497	412	412
query50	980	361	257	257
query51	4372	4388	4253	4253
query52	107	104	98	98
query53	258	284	209	209
query54	325	267	258	258
query55	95	91	90	90
query56	311	328	334	328
query57	1441	1421	1298	1298
query58	298	270	280	270
query59	1603	1663	1462	1462
query60	334	319	312	312
query61	155	151	155	151
query62	706	645	592	592
query63	252	205	211	205
query64	2397	842	622	622
query65	
query66	1678	492	360	360
query67	29246	29739	29545	29545
query68	
query69	473	344	310	310
query70	1000	1059	1069	1059
query71	306	284	275	275
query72	3048	2768	2420	2420
query73	890	788	435	435
query74	5111	4993	4809	4809
query75	2707	2615	2264	2264
query76	2274	1169	764	764
query77	414	420	343	343
query78	12467	12492	11823	11823
query79	1446	1004	761	761
query80	687	539	454	454
query81	467	282	240	240
query82	1374	157	124	124
query83	328	271	252	252
query84	263	142	115	115
query85	903	538	452	452
query86	392	341	336	336
query87	3454	3392	3256	3256
query88	3629	2761	2749	2749
query89	455	393	345	345
query90	1933	186	191	186
query91	186	170	141	141
query92	80	74	79	74
query93	1562	1422	830	830
query94	555	364	300	300
query95	670	383	437	383
query96	1117	794	375	375
query97	2744	2746	2606	2606
query98	235	229	226	226
query99	1181	1154	1041	1041
Total cold run time: 254570 ms
Total hot run time: 172873 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 75.15% (127/169) 🎉
Increment coverage report
Complete coverage report

englefly and others added 2 commits May 28, 2026 14:38
…rojection

The final PhysicalProject above Materialize appended all pulled-up
expressions at the end regardless of their original position in
userVisibleOutput. When a nested expression (struct_element,
element_at, etc.) was not the last SELECT column, the result
schema was swapped.

Fix by building outputExprs in userVisibleOutput order, replacing
each pulled-up slot in-place with its corresponding expression
via pulledUpExprMap, so output columns match the SQL SELECT order.

Add regression tests (struct/variant/map nested expr before id).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@englefly
Copy link
Copy Markdown
Contributor Author

run buildall

@englefly
Copy link
Copy Markdown
Contributor Author

/review

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 31456 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 80a6ff0127dca6e6fe6f5ed9f4e0477ab0281d2c, 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	17611	4093	4047	4047
q2	q3	10764	1404	848	848
q4	4687	474	345	345
q5	7600	2302	2126	2126
q6	251	180	142	142
q7	1011	761	676	676
q8	9367	1634	1620	1620
q9	6470	4992	4957	4957
q10	6447	2204	1893	1893
q11	432	283	247	247
q12	695	435	304	304
q13	18216	3396	2813	2813
q14	271	257	238	238
q15	q16	820	780	720	720
q17	998	957	1001	957
q18	6959	5730	5597	5597
q19	1291	1339	977	977
q20	516	418	269	269
q21	5669	2607	2386	2386
q22	439	353	294	294
Total cold run time: 100514 ms
Total hot run time: 31456 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	4407	4413	4438	4413
q2	q3	4524	4943	4363	4363
q4	2105	2246	1393	1393
q5	4465	4306	4760	4306
q6	263	201	151	151
q7	1935	1929	1676	1676
q8	2635	2256	2268	2256
q9	7993	7875	8094	7875
q10	4804	4820	4346	4346
q11	578	423	397	397
q12	804	739	548	548
q13	3284	3751	2984	2984
q14	310	313	275	275
q15	q16	735	733	644	644
q17	1396	1357	1357	1357
q18	8031	7329	7136	7136
q19	1129	1107	1100	1100
q20	2228	2225	1941	1941
q21	5302	4615	4503	4503
q22	539	484	423	423
Total cold run time: 57467 ms
Total hot run time: 52087 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 172620 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 80a6ff0127dca6e6fe6f5ed9f4e0477ab0281d2c, data reload: false

query5	4336	685	531	531
query6	365	240	202	202
query7	4306	577	318	318
query8	331	239	223	223
query9	8773	4109	4072	4072
query10	471	361	300	300
query11	5820	2436	2243	2243
query12	199	126	126	126
query13	1308	598	446	446
query14	6169	5540	5209	5209
query14_1	4558	4531	4504	4504
query15	219	209	183	183
query16	991	463	431	431
query17	1168	749	618	618
query18	2529	483	360	360
query19	221	219	171	171
query20	144	144	132	132
query21	219	146	127	127
query22	13703	13518	13374	13374
query23	17306	16436	16220	16220
query23_1	16380	16310	16412	16310
query24	7549	1811	1390	1390
query24_1	1364	1366	1314	1314
query25	587	496	461	461
query26	1388	357	186	186
query27	2732	613	355	355
query28	4450	2011	2017	2011
query29	996	640	540	540
query30	307	245	205	205
query31	1139	1090	959	959
query32	89	77	81	77
query33	573	374	314	314
query34	1188	1179	677	677
query35	817	806	769	769
query36	1400	1409	1225	1225
query37	158	111	92	92
query38	3233	3173	3051	3051
query39	932	916	889	889
query39_1	874	880	900	880
query40	243	149	126	126
query41	65	64	63	63
query42	110	111	112	111
query43	344	349	300	300
query44	
query45	216	203	195	195
query46	1086	1224	741	741
query47	2344	2350	2236	2236
query48	422	433	294	294
query49	626	496	391	391
query50	1009	347	247	247
query51	4389	4265	4457	4265
query52	108	108	95	95
query53	255	279	206	206
query54	315	287	254	254
query55	94	92	90	90
query56	321	300	314	300
query57	1432	1403	1345	1345
query58	303	274	277	274
query59	1666	1711	1486	1486
query60	321	328	326	326
query61	164	159	158	158
query62	698	647	584	584
query63	260	204	206	204
query64	2386	813	639	639
query65	
query66	1729	473	359	359
query67	29821	29709	29555	29555
query68	
query69	503	350	304	304
query70	1036	1010	1028	1010
query71	322	318	272	272
query72	3050	2692	2443	2443
query73	814	812	441	441
query74	5137	4994	4804	4804
query75	2839	2593	2260	2260
query76	2293	1171	789	789
query77	410	421	340	340
query78	12464	12388	11943	11943
query79	1464	1095	760	760
query80	662	549	464	464
query81	454	279	250	250
query82	1352	160	130	130
query83	365	281	259	259
query84	262	146	109	109
query85	888	534	465	465
query86	416	363	326	326
query87	3448	3377	3259	3259
query88	3678	2757	2685	2685
query89	453	393	345	345
query90	1958	192	185	185
query91	180	170	137	137
query92	84	82	75	75
query93	1479	1453	874	874
query94	553	352	317	317
query95	700	489	349	349
query96	1125	748	345	345
query97	2722	2730	2606	2606
query98	238	232	224	224
query99	1190	1153	1014	1014
Total cold run time: 255396 ms
Total hot run time: 172620 ms

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.

Summary:

This PR is not ready as-is. I found one additional test issue, and the already-open inline thread about final projection ordering still appears applicable at the current head: the final projection still appends pulled-up expressions after non-pulled slots, so nested expressions before later selected columns can return columns in the wrong order. I did not duplicate that existing inline comment.

Critical checkpoint conclusions:

  • Goal and proof: The goal is to extend TopN lazy materialization to nested/PPD expressions and verify nested pruning. The implementation partially targets that, but current evidence is insufficient because the added column-order qt_ checks are missing expected output, and the existing projection-order correctness issue remains.
  • Scope and clarity: The change is focused on TopN lazy materialization and explain/test coverage, but the plan restructuring path is complex and must preserve output ordering exactly.
  • Concurrency: No new shared mutable concurrent state or FE locking path was introduced in the reviewed changes.
  • Lifecycle/static initialization: No new special lifecycle or cross-TU/static initialization concerns found.
  • Configuration: No new configuration item was added. Existing session variables are used.
  • Compatibility: No storage format or FE-BE protocol incompatibility found in the reviewed diff.
  • Parallel code paths: The change targets the Nereids TopN lazy-materialization path; I did not find another directly equivalent modified path requiring the same patch.
  • Conditional checks: The added shape checks skip unsupported plan shapes; the risky final-output condition is already covered by the existing review thread.
  • Test coverage: Added regression coverage exists, but the new result blocks are incomplete in the .out file, so the suite will fail or not validate the intended cases correctly.
  • Test results: The .out file is missing expected results for the newly added column-order qt_ labels.
  • Observability: Existing explain output is extended for nested columns; no additional runtime observability requirement found.
  • Transaction/persistence/data writes: Not applicable to this optimizer/post-processing change.
  • FE-BE variable passing: No new transmitted variable requiring scattered send-path updates found.
  • Performance: No obvious hot-path performance regression beyond the existing complexity of the post-processing rewrite.
  • User focus: No additional user-provided review focus was specified.

@englefly
Copy link
Copy Markdown
Contributor Author

run buildall

@englefly englefly marked this pull request as ready for review May 28, 2026 15:06
@englefly
Copy link
Copy Markdown
Contributor Author

run buildall

@englefly
Copy link
Copy Markdown
Contributor Author

run buildall

@englefly
Copy link
Copy Markdown
Contributor 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.

Automated review summary:

Requesting changes for one new blocking regression-test issue. I read the existing inline review threads first and did not re-submit the already-known topn_lazy_nested_column_pruning output mismatch or the earlier column-order issue.

Critical checkpoint conclusions:

  • Goal/test proof: the PR aims to expand TopN lazy materialization by pulling projection expressions above TopN. The implementation is accompanied by regression coverage, but one new suite cannot pass because its expected-result file is missing.
  • Scope/focus: the code changes are mostly focused on Nereids TopN expression pull-up and lazy materialization.
  • Concurrency/lifecycle: no new concurrent state, locking path, or special lifecycle concern was found in the reviewed changes.
  • Configuration: a new experimental session variable is added and forwarded; no dynamic config issue found.
  • Compatibility/persistence: no storage format, EditLog, or FE-BE thrift compatibility issue found beyond existing lazy materialization protocol usage.
  • Parallel code paths: Nereids logical rewrite and post-physical lazy materialization paths were both considered; no additional parallel-path blocker found.
  • Test coverage/results: blocking issue below; also, the existing thread already covers missing labels in topn_lazy_nested_column_pruning.out.
  • Observability/performance/data correctness: no additional blocker found in these areas during review.

User focus: no additional user-provided review focus was specified.

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 32411 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit d2315196727fc105b516bd6d181ac447bc29f8e8, 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	17679	4194	4169	4169
q2	q3	10794	1426	850	850
q4	4687	491	336	336
q5	7538	2441	2193	2193
q6	250	189	140	140
q7	976	791	632	632
q8	9359	1696	1557	1557
q9	5287	5048	5056	5048
q10	6359	2191	1864	1864
q11	439	291	261	261
q12	635	458	299	299
q13	18193	3496	2807	2807
q14	266	258	228	228
q15	q16	816	775	710	710
q17	1016	1043	1039	1039
q18	7019	5593	5577	5577
q19	1298	1368	1278	1278
q20	561	452	271	271
q21	6414	2904	2843	2843
q22	451	371	309	309
Total cold run time: 100037 ms
Total hot run time: 32411 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	5145	5006	4990	4990
q2	q3	4986	5370	4592	4592
q4	2121	2243	1382	1382
q5	5119	4780	4788	4780
q6	260	197	133	133
q7	1941	1728	1534	1534
q8	2574	2260	2301	2260
q9	7713	7566	7501	7501
q10	4790	4684	4244	4244
q11	545	376	346	346
q12	738	754	531	531
q13	3082	3477	2837	2837
q14	279	291	267	267
q15	q16	678	698	592	592
q17	1294	1276	1271	1271
q18	7529	7003	6916	6916
q19	1092	1088	1152	1088
q20	2236	2213	1926	1926
q21	5324	4615	4497	4497
q22	507	455	401	401
Total cold run time: 57953 ms
Total hot run time: 52088 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 171814 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 d2315196727fc105b516bd6d181ac447bc29f8e8, data reload: false

query5	4314	663	522	522
query6	337	230	213	213
query7	4225	600	310	310
query8	333	244	229	229
query9	8795	4102	4077	4077
query10	457	361	306	306
query11	5713	2482	2293	2293
query12	186	130	123	123
query13	1274	609	439	439
query14	6120	5463	5194	5194
query14_1	4490	4480	4471	4471
query15	214	207	192	192
query16	1051	470	462	462
query17	1194	720	582	582
query18	2716	482	355	355
query19	223	199	168	168
query20	136	130	128	128
query21	217	144	119	119
query22	13694	13562	13453	13453
query23	17334	16432	16218	16218
query23_1	16394	16320	16383	16320
query24	7420	1793	1323	1323
query24_1	1318	1313	1326	1313
query25	584	473	404	404
query26	1300	326	175	175
query27	2683	559	354	354
query28	4408	2030	2010	2010
query29	970	622	495	495
query30	308	243	199	199
query31	1136	1081	953	953
query32	93	74	74	74
query33	529	352	303	303
query34	1175	1170	663	663
query35	780	786	703	703
query36	1369	1458	1257	1257
query37	150	107	93	93
query38	3221	3167	3120	3120
query39	929	938	907	907
query39_1	880	885	868	868
query40	236	145	123	123
query41	67	63	63	63
query42	142	107	113	107
query43	323	338	284	284
query44	
query45	211	205	195	195
query46	1105	1183	766	766
query47	2372	2327	2196	2196
query48	407	406	294	294
query49	643	496	382	382
query50	987	350	261	261
query51	4338	4289	4285	4285
query52	102	107	100	100
query53	253	282	214	214
query54	313	279	252	252
query55	93	93	90	90
query56	300	293	314	293
query57	1430	1408	1324	1324
query58	297	276	258	258
query59	1592	1690	1451	1451
query60	319	323	307	307
query61	160	158	153	153
query62	700	648	586	586
query63	245	197	212	197
query64	2395	814	638	638
query65	
query66	1690	484	370	370
query67	29679	29656	29550	29550
query68	
query69	475	349	302	302
query70	1002	1014	1041	1014
query71	317	278	268	268
query72	3003	2726	2436	2436
query73	847	747	437	437
query74	5141	5013	4842	4842
query75	2701	2591	2269	2269
query76	2299	1178	785	785
query77	414	420	343	343
query78	12365	12326	11815	11815
query79	1277	1073	793	793
query80	613	543	458	458
query81	444	283	250	250
query82	240	159	127	127
query83	277	280	247	247
query84	
query85	847	527	444	444
query86	357	346	309	309
query87	3463	3399	3284	3284
query88	3676	2756	2742	2742
query89	419	395	342	342
query90	2190	189	177	177
query91	177	163	139	139
query92	84	77	78	77
query93	1465	1469	959	959
query94	552	361	312	312
query95	678	465	363	363
query96	1052	786	351	351
query97	2734	2734	2620	2620
query98	236	228	227	227
query99	1158	1164	1030	1030
Total cold run time: 252731 ms
Total hot run time: 171814 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 31458 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 835b604c4ad63b88f63c6caeb098d12c98a4be08, 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	17711	4086	4003	4003
q2	q3	10756	1372	803	803
q4	4690	478	347	347
q5	7667	2294	2086	2086
q6	241	179	138	138
q7	942	797	643	643
q8	9370	1681	1654	1654
q9	5198	4916	4913	4913
q10	6383	2206	1879	1879
q11	441	269	242	242
q12	636	428	298	298
q13	18111	3373	2774	2774
q14	261	257	238	238
q15	q16	816	767	710	710
q17	907	957	970	957
q18	6898	5728	5506	5506
q19	1320	1248	970	970
q20	521	511	345	345
q21	6190	2745	2626	2626
q22	457	377	326	326
Total cold run time: 99516 ms
Total hot run time: 31458 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	5011	4698	4737	4698
q2	q3	4778	5307	4657	4657
q4	2147	2189	1394	1394
q5	4850	4915	4683	4683
q6	227	182	127	127
q7	1791	1744	1639	1639
q8	2427	2103	2111	2103
q9	7968	7987	7350	7350
q10	4745	4703	4198	4198
q11	526	383	349	349
q12	738	733	524	524
q13	3036	3439	2784	2784
q14	273	283	265	265
q15	q16	699	693	610	610
q17	1273	1249	1250	1249
q18	7201	6753	6771	6753
q19	1148	1106	1067	1067
q20	2205	2226	1948	1948
q21	5250	4561	4404	4404
q22	508	459	413	413
Total cold run time: 56801 ms
Total hot run time: 51215 ms

englefly and others added 5 commits June 2, 2026 17:18
### What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary: Add a focused unit test for the minimal TopN pull-up pattern where an upper Project forwards a slot produced by a lower Project. The test documents that the forwarding Project must pass through the expression input slot after the lower Project removes the pulled-up expression.

### Release note

None

### Check List (For Author)

- Test: Unit Test

    - mvn -f fe/pom.xml test -pl fe-core -am -Dmaven.build.cache.enabled=false -Dtest=PullUpProjectExprUnderTopNTest#testPullUpThroughForwardedSlotFromLowerProject -DfailIfNoTests=false -DskipITs -Dcheckstyle.skip -Dspotless.check.skip=true

- Behavior changed: No

- Does this need documentation: No

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
### What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary: Add an explanatory comment for simplifyProject with the forwarded-slot pattern it handles after TopN expression pull-up.

### Release note

None

### Check List (For Author)

- Test: Manual test

    - cd fe && mvn checkstyle:check -pl fe-core -DskipTests

- Behavior changed: No

- Does this need documentation: No

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
### What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary: PullUpProjectExprUnderTopN could restore a pulled-up expression above TopN without preserving the expression's input slots through the TopN. When combined with TopN pushdown through Project and Join, required base columns such as k2 could be pruned from the join child output while an upper Project still referenced them, producing an invalid plan. This change keeps pulled-up expression inputs as pass-through slots and makes TopN-through-Project-Join pushdown preserve Project input slots on the pushed side.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - mvn -f fe/pom.xml test -pl fe-core -am -Dmaven.build.cache.enabled=false -Dtest=PullUpProjectExprUnderTopNTest,PushDownTopNThroughJoinTest -DfailIfNoTests=false -DskipITs -Dcheckstyle.skip -Dspotless.check.skip=true
    - cd fe && mvn checkstyle:check -pl fe-core -DskipTests
- Behavior changed: No
- Does this need documentation: No

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
### What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary: Fix several TopN lazy materialization and TopN expression pull-up regressions found by review10. Lazy TopN no longer used OperativeColumnDerive, so MOR/AGG/PRIMARY key columns could be lazily materialized incorrectly; the key-column requirement is now collected in LazyMaterializeTopN and removed from OperativeColumnDerive. TopN through Join now preserves join condition slots when pushing TopN to one side. TopN expression pull-up now avoids score() and variant-slot expressions, and resolves aliases that reference unavailable pulled-up slots. The topn_expr_pullup expected output is regenerated for the added join cases.

### Release note

None

### Check List (For Author)

- Test: Regression test / Unit Test
    - ./run-regression-test.sh --run -d query_p0/topn_lazy -s topn_lazy_on_data_model
    - ./run-regression-test.sh --run -f regression-test/suites/variant_p0/rqg/rqg5.sql
    - ./run-regression-test.sh --run -d nereids_rules_p0/column_pruning -s null_column_pruning
    - ./run-regression-test.sh --run -d inverted_index_p0 -s test_bm25_score
    - ./run-regression-test.sh --run -d nereids_rules_p0/column_pruning -s topn_expr_pullup
    - ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.PullUpProjectExprUnderTopNTest
    - cd fe && mvn checkstyle:check -pl fe-core
- Behavior changed: No
- Does this need documentation: No

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@englefly
Copy link
Copy Markdown
Contributor Author

englefly commented Jun 2, 2026

/review

@englefly
Copy link
Copy Markdown
Contributor Author

englefly commented Jun 2, 2026

run buildall

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.

I found a blocking correctness regression in the latest TopN expression pull-up changes. The rule can now expose internal pass-through base slots as columns of the upper project, so a query that originally returns N columns can be rewritten to return N+M columns.

Critical checkpoints:

  • Goal/test: the PR aims to pull eligible project expressions above TopN while preserving query semantics and enabling lazy materialization. Current code does not fully accomplish this because the restored project can change output arity; existing tests even assert the extra output in some cases, so coverage needs correction.
  • Scope/focus: the change is focused, but the pass-through-slot fix leaks implementation slots into user-visible output.
  • Concurrency/lifecycle/config: no relevant concurrency, lifecycle, or config concerns found in the reviewed FE optimizer paths.
  • Compatibility/persistence/transactions/data writes: no storage-format, EditLog, transaction, or data-write compatibility concerns found.
  • Parallel paths: the issue is specific to the new PullUpProjectExprUnderTopN upper-project reconstruction; previously reported LazyMaterializeTopN output-order and ordinal-mapping issues are separate known threads and were not duplicated.
  • Test coverage: tests need to assert the rewritten root output still matches the original query output count/order, and regression output should cover this.
  • Observability/performance: no additional observability requirement; performance benefits are secondary until semantic preservation is fixed.

User focus: no additional user-provided review focus was specified.

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: PullUpProjectExprUnderTopN restored pulled expressions above TopN, but also appended the input slots used only to compute those expressions into the restored upper Project output. For a root Project such as [x = a + 1, b, id], this exposed internal pass-through slot a and changed the user-visible schema to [x, a, b, id]. The fix keeps required input slots available below TopN while restoring only the original TopN output columns in the upper Project.

### Release note

None

### Check List (For Author)

- Test: Unit Test

    - ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.PullUpProjectExprUnderTopNTest

    - cd fe && mvn checkstyle:check -pl fe-core

- Behavior changed: No

- Does this need documentation: No

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@englefly
Copy link
Copy Markdown
Contributor Author

englefly commented Jun 2, 2026

run buildall

@englefly
Copy link
Copy Markdown
Contributor Author

englefly commented Jun 2, 2026

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

Review summary:

I found one additional blocking issue beyond the already-known TopN output-shape/order threads: the new logical TopN expression pull-up can move volatile/unique functions across TopN.

Critical checkpoint conclusions:

  • Goal/test: the PR aims to expand TopN lazy materialization. There are tests for many deterministic expression cases, but no volatile-expression negative test for the new pull-up rule.
  • Scope/focus: the implementation is broad but mostly focused on TopN lazy materialization. The issue is in the core new rewrite rule and affects default-on behavior.
  • Concurrency/lifecycle/config: no new concurrency or lifecycle blocker found. The new session variable is forwardable and gated, but default-on behavior increases the impact of the rewrite bug.
  • Compatibility/persistence/transactions: no storage-format, EditLog, or transaction persistence changes found.
  • Parallel paths: volatile-expression safeguards should match other Nereids rewrite rules that avoid moving containsVolatileExpression() expressions.
  • Tests/results: regression .out files are now present for the earlier missing-output concerns, but coverage is still missing for the issue in this comment.
  • Observability/performance: no additional observability blocker found. Performance motivation is clear, but correctness must take precedence.

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

### What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary: TopN lazy materialization can wrap the original physical olap scan with PhysicalLazyMaterializeOlapScan. The topn-filter target relation may be recorded with the wrapper while the legacy OlapScanNode is generated from the inner scan, or vice versa, so relation-key lookup can miss the target and the legacy scan is not registered for TOPN OPT. Physical result sinks also expose final select-list output expressions, which can make select * mark every scan output as an operative slot if OperativeColumnDerive is run on the physical sink tree. This change skips PhysicalResultSink output expressions when deriving operative slots and makes TopnFilterContext translate lazy materialize olap scan targets through the inner scan as well.

### Release note

None

### Check List (For Author)

- Test: Unit Test

    - ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.OperativeColumnDeriveTest,org.apache.doris.nereids.postprocess.TopNRuntimeFilterTest

    - cd fe && mvn checkstyle:check -pl fe-core

    - Manual test: explain select * from orders order by o_orderkey limit 10 shows TOPN OPT:1 on local cluster

    - Regression test attempted: ./run-regression-test.sh --run -d nereids_tpch_p0/tpch -s topn-filter; explain checks passed but qt_complexTopn failed because current cluster returned empty results

- Behavior changed: No

- Does this need documentation: No

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hello-stephen
Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 72.03% (327/454) 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 29408 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 17045ff0b7bfb226e39b0e057cf8c19fdd0947e4, 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	17594	4208	4266	4208
q2	q3	10775	1397	808	808
q4	4689	481	340	340
q5	7633	875	587	587
q6	176	171	138	138
q7	774	850	628	628
q8	9351	1536	1598	1536
q9	5789	4493	4534	4493
q10	6821	1787	1550	1550
q11	434	277	250	250
q12	625	437	289	289
q13	18146	3394	2733	2733
q14	270	255	247	247
q15	q16	803	787	704	704
q17	944	965	1000	965
q18	6811	5727	5560	5560
q19	1318	1289	1076	1076
q20	532	404	256	256
q21	6217	2836	2727	2727
q22	458	380	313	313
Total cold run time: 100160 ms
Total hot run time: 29408 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	5072	4791	4823	4791
q2	q3	4903	5307	4708	4708
q4	2103	2200	1383	1383
q5	4800	4946	4739	4739
q6	239	178	129	129
q7	1871	1758	1607	1607
q8	2435	2085	2073	2073
q9	7973	7776	7447	7447
q10	4751	4655	4253	4253
q11	532	383	345	345
q12	728	733	527	527
q13	2983	3393	2841	2841
q14	268	276	252	252
q15	q16	675	697	600	600
q17	1264	1239	1235	1235
q18	7312	7061	6862	6862
q19	1119	1086	1105	1086
q20	2211	2216	1939	1939
q21	5258	4549	4420	4420
q22	514	488	399	399
Total cold run time: 57011 ms
Total hot run time: 51636 ms

### What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary: TopN lazy materialization should allow payload sub-path expressions such as substring(element_at(payload, 'name'), 1) to be pulled above TopN so the scan can keep nested column pruning and defer the expression to VMaterializeNode. A previous conservative guard rejected every expression containing a VARIANT slot, which forced payload.name to be computed in the scan final projections and broke topn_lazy_nested_column_pruning. Remove that broad VARIANT guard while keeping the existing non-movable function and score() protections.

### Release note

None

### Check List (For Author)

- Test: Regression test / Unit Test
    - ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.PullUpProjectExprUnderTopNTest
    - cd fe && mvn checkstyle:check -pl fe-core
    - ./build.sh --fe
    - ./run-regression-test.sh --run -d nereids_rules_p0/column_pruning -s topn_lazy_nested_column_pruning
- Behavior changed: No
- Does this need documentation: No

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 29058 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 14da24479173944ea5601dd5c550fa43e7079e0d, 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	17718	3979	3983	3979
q2	q3	10764	1371	801	801
q4	4689	464	340	340
q5	7591	872	595	595
q6	182	167	134	134
q7	796	865	628	628
q8	9427	1570	1643	1570
q9	5893	4441	4478	4441
q10	6753	1814	1571	1571
q11	439	273	253	253
q12	626	422	288	288
q13	18105	3341	2729	2729
q14	267	252	243	243
q15	q16	825	766	709	709
q17	995	1012	850	850
q18	7185	5891	5652	5652
q19	1292	1305	1008	1008
q20	495	411	259	259
q21	6239	2773	2694	2694
q22	480	386	314	314
Total cold run time: 100761 ms
Total hot run time: 29058 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	5052	4704	4757	4704
q2	q3	4836	5327	4621	4621
q4	2130	2214	1381	1381
q5	4736	4849	4619	4619
q6	235	178	136	136
q7	1875	1875	1577	1577
q8	2438	2053	2071	2053
q9	7800	7424	7307	7307
q10	4786	4685	4229	4229
q11	522	379	347	347
q12	719	734	521	521
q13	2969	3361	2797	2797
q14	270	289	249	249
q15	q16	672	694	608	608
q17	1272	1242	1237	1237
q18	7215	6700	6658	6658
q19	1132	1073	1123	1073
q20	2203	2218	1944	1944
q21	5240	4548	4393	4393
q22	506	446	419	419
Total cold run time: 56608 ms
Total hot run time: 50873 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 169813 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 17045ff0b7bfb226e39b0e057cf8c19fdd0947e4, data reload: false

query5	4325	670	478	478
query6	444	198	177	177
query7	4922	576	304	304
query8	379	225	193	193
query9	8766	3966	3987	3966
query10	467	303	265	265
query11	5972	2365	2188	2188
query12	157	103	97	97
query13	1275	553	431	431
query14	6407	5364	5075	5075
query14_1	4373	4386	4368	4368
query15	210	194	174	174
query16	992	452	412	412
query17	1056	689	563	563
query18	2460	473	336	336
query19	208	182	137	137
query20	113	107	105	105
query21	223	138	117	117
query22	13790	13619	13389	13389
query23	17499	16574	16146	16146
query23_1	16369	16345	16306	16306
query24	7560	1762	1298	1298
query24_1	1298	1320	1313	1313
query25	569	474	403	403
query26	1295	321	170	170
query27	2717	574	369	369
query28	4453	1993	1988	1988
query29	1101	618	516	516
query30	314	231	201	201
query31	1168	1093	1000	1000
query32	118	74	61	61
query33	538	336	266	266
query34	1184	1139	672	672
query35	790	794	692	692
query36	1411	1404	1236	1236
query37	155	108	98	98
query38	3209	3168	3047	3047
query39	925	913	900	900
query39_1	911	883	871	871
query40	223	131	106	106
query41	72	68	67	67
query42	102	110	105	105
query43	333	319	279	279
query44	
query45	205	189	188	188
query46	1109	1167	773	773
query47	2383	2497	2299	2299
query48	412	413	311	311
query49	648	481	380	380
query50	982	357	265	265
query51	4326	4310	4292	4292
query52	91	91	77	77
query53	247	275	199	199
query54	288	232	226	226
query55	80	76	72	72
query56	261	243	241	241
query57	1450	1420	1348	1348
query58	259	231	222	222
query59	1628	1663	1437	1437
query60	320	265	239	239
query61	194	157	154	154
query62	689	646	594	594
query63	229	189	186	186
query64	2525	769	614	614
query65	
query66	1803	471	346	346
query67	29818	29776	29560	29560
query68	
query69	426	294	253	253
query70	973	907	949	907
query71	306	229	213	213
query72	2882	2679	2408	2408
query73	840	764	426	426
query74	5139	4979	4822	4822
query75	2666	2615	2245	2245
query76	2350	1165	775	775
query77	372	375	283	283
query78	12598	12527	11966	11966
query79	1442	1036	748	748
query80	848	479	396	396
query81	490	285	251	251
query82	819	154	134	134
query83	366	283	242	242
query84	
query85	886	533	431	431
query86	406	298	290	290
query87	3414	3380	3232	3232
query88	3636	2724	2735	2724
query89	425	387	330	330
query90	1807	185	178	178
query91	179	160	136	136
query92	68	60	57	57
query93	1430	1478	857	857
query94	634	353	311	311
query95	683	392	354	354
query96	1048	784	346	346
query97	2729	2690	2555	2555
query98	214	213	222	213
query99	1150	1187	1060	1060
Total cold run time: 252561 ms
Total hot run time: 169813 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 169019 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 14da24479173944ea5601dd5c550fa43e7079e0d, data reload: false

query5	4321	630	486	486
query6	457	201	181	181
query7	4827	595	300	300
query8	374	219	203	203
query9	8745	3969	3986	3969
query10	453	310	261	261
query11	5867	2350	2147	2147
query12	161	104	108	104
query13	1264	601	416	416
query14	6436	5429	5094	5094
query14_1	4399	4372	4395	4372
query15	211	198	176	176
query16	1006	471	449	449
query17	946	710	589	589
query18	2469	481	352	352
query19	206	187	146	146
query20	116	108	110	108
query21	221	142	117	117
query22	13586	13643	13421	13421
query23	17218	16419	16183	16183
query23_1	16364	16248	16232	16232
query24	7735	1732	1319	1319
query24_1	1329	1296	1306	1296
query25	570	446	378	378
query26	1316	326	161	161
query27	2672	574	356	356
query28	4447	2026	1974	1974
query29	1083	592	478	478
query30	310	240	205	205
query31	1117	1082	938	938
query32	110	61	62	61
query33	517	315	259	259
query34	1162	1143	649	649
query35	750	789	685	685
query36	1403	1432	1245	1245
query37	154	105	89	89
query38	3212	3151	3017	3017
query39	945	933	915	915
query39_1	892	868	869	868
query40	234	131	102	102
query41	67	62	64	62
query42	96	95	92	92
query43	315	319	280	280
query44	
query45	196	185	178	178
query46	1074	1193	712	712
query47	2379	2375	2249	2249
query48	396	431	310	310
query49	630	467	362	362
query50	957	334	252	252
query51	4337	4265	4219	4219
query52	88	87	76	76
query53	238	261	191	191
query54	264	235	202	202
query55	78	75	69	69
query56	262	218	212	212
query57	1420	1414	1330	1330
query58	251	217	210	210
query59	1520	1619	1426	1426
query60	290	252	233	233
query61	174	164	168	164
query62	711	648	605	605
query63	239	188	191	188
query64	2593	787	619	619
query65	
query66	1844	478	348	348
query67	29714	29731	29511	29511
query68	
query69	426	300	268	268
query70	972	983	912	912
query71	298	229	208	208
query72	3090	2648	2379	2379
query73	889	747	436	436
query74	5119	4951	4742	4742
query75	2662	2595	2277	2277
query76	2328	1186	799	799
query77	362	372	296	296
query78	12380	12368	11880	11880
query79	1301	1027	733	733
query80	617	486	394	394
query81	455	278	239	239
query82	589	155	119	119
query83	363	277	247	247
query84	
query85	881	533	439	439
query86	373	294	283	283
query87	3387	3371	3215	3215
query88	3639	2752	2695	2695
query89	416	381	329	329
query90	1931	181	173	173
query91	185	163	139	139
query92	62	58	58	58
query93	1490	1412	866	866
query94	536	353	318	318
query95	671	483	345	345
query96	1043	822	330	330
query97	2745	2723	2559	2559
query98	220	205	204	204
query99	1162	1178	1038	1038
Total cold run time: 250614 ms
Total hot run time: 169019 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 77.53% (352/454) 🎉
Increment coverage report
Complete coverage report

…ubquery

When a correlated scalar subquery appears in a LEFT OUTER JOIN ON clause,
a nested TopN is created by LIMIT pushdown. The inner TopN's collector
used fresh blockedExprIds that did not inherit outer join condition slots,
allowing expressions like element_at(var) to be pulled up from projects
below the inner TopN. This triggered a cascade where downstream projects
were simplified, intermediate Joins were rebuilt, and eventually the
aggregate result slot (AVG) from the correlated subquery was lost during
project reconstruction, crashing addUpperProject.

Fix:
1. (root cause) CollectorContext now tracks outer blockedExprIds for
   nested TopNs via collectFromNode. The inner TopN's visitLogicalTopN
   merges them so join condition slots correctly block pull-up.
2. (safety net) addUpperProject handles missing slots gracefully by
   passing them through directly instead of crashing.

Add regression test testCorrelatedSubqueryWithNestedTopN.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@englefly
Copy link
Copy Markdown
Contributor Author

englefly commented Jun 3, 2026

run buildall

@englefly
Copy link
Copy Markdown
Contributor Author

englefly commented Jun 3, 2026

/review

@englefly
Copy link
Copy Markdown
Contributor Author

englefly commented Jun 3, 2026

run buildall

@englefly englefly marked this pull request as ready for review June 3, 2026 13:57
@englefly
Copy link
Copy Markdown
Contributor Author

englefly commented Jun 3, 2026

run buildall

@englefly
Copy link
Copy Markdown
Contributor Author

englefly commented Jun 3, 2026

/review

@hello-stephen
Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 72.65% (340/468) 🎉
Increment coverage report
Complete coverage report

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