Skip to content

[fix](fe) Fix assert row join pushdown alias handling#63892

Open
morrySnow wants to merge 2 commits into
apache:masterfrom
morrySnow:fix-join-assert-row
Open

[fix](fe) Fix assert row join pushdown alias handling#63892
morrySnow wants to merge 2 commits into
apache:masterfrom
morrySnow:fix-join-assert-row

Conversation

@morrySnow
Copy link
Copy Markdown
Contributor

@morrySnow morrySnow commented May 29, 2026

What problem does this PR solve?

Issue Number: None

Related PR: #57414

Problem Summary: A scalar subquery comparison can reference a projected alias from the right side of an inner join. PushDownJoinOnAssertNumRows previously identified the pushed condition slots against the project output after rewriting the condition through the project, so aliases expanded to right-child slots could be treated as if no bottom-join slots were involved and the alias projection could be attached to the left child. The rewritten plan then referenced slots that were absent from that child. This change determines slot ownership from the bottom join output after project pushdown, keeps the original pushdown child order when assembling the new join, and adds a unit test for the right-child alias case.

Release note

Fix query planning failure for scalar subquery comparisons on projected join expressions.

Check List (For Author)

  • Test:
    • Unit Test: ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.PushDownJoinOnAssertNumRowsTest
  • Behavior changed: Yes. The rewrite now keeps predicates on the child that actually provides the referenced slots.
  • Does this need documentation: No

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: A scalar subquery comparison can reference a projected alias from the right side of an inner join. PushDownJoinOnAssertNumRows previously identified the pushed condition slots against the project output after rewriting the condition through the project, so aliases expanded to right-child slots could be treated as if no bottom-join slots were involved and the alias projection could be attached to the left child. The rewritten plan then referenced slots that were absent from that child. This change determines slot ownership from the bottom join output after project pushdown, keeps the original pushdown child order when assembling the new join, and adds a unit test for the right-child alias case.

### Release note

Fix query planning failure for scalar subquery comparisons on projected join expressions.

### Check List (For Author)

- Test:
    - Unit Test: ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.PushDownJoinOnAssertNumRowsTest
- Behavior changed: Yes. The rewrite now keeps predicates on the child that actually provides the referenced slots.
- Does this need documentation: No
@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?

@morrySnow
Copy link
Copy Markdown
Contributor Author

/review

@morrySnow morrySnow requested review from Copilot and englefly May 29, 2026 05:28
@morrySnow
Copy link
Copy Markdown
Contributor Author

run buildall

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a Nereids optimizer rewrite so scalar subquery join predicates using projected aliases are pushed down to the bottom-join child that actually provides the referenced slots.

Changes:

  • Determines predicate slot ownership from the bottom join output after project pushdown.
  • Refactors join reconstruction into a helper that preserves child ordering.
  • Adds a unit test covering a right-child projected alias predicate.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownJoinOnAssertNumRows.java Updates pushdown slot ownership logic and join assembly.
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/PushDownJoinOnAssertNumRowsTest.java Adds regression coverage for right-child alias handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

No blocking issues found in the changed Nereids rule or the added unit test. The fix determines condition slot ownership after project pushdown against the bottom join output, preserves the original bottom-join child order when pushing to the right child, and keeps the upper project wrapper so alias slots remain available.

Critical checkpoint conclusions:

  • Goal and proof: The PR addresses the right-child projected alias case for PushDownJoinOnAssertNumRows, and the added unit test covers that shape.
  • Scope: The implementation is focused on the existing rule and test, with no new rule registration or unrelated behavior.
  • Concurrency and lifecycle: Not applicable; this is a logical rewrite rule with no shared mutable runtime state or special lifecycle management.
  • Configuration and compatibility: No new configuration, storage format, or FE-BE protocol compatibility concerns.
  • Parallel code paths: The existing left/right pushdown paths are both routed through the helper, and the right-child alias case is now covered.
  • Conditional checks: The new empty bottom-join slot guard is safe and prevents transforming scalar-only/project-only conditions that cannot be assigned to one bottom child.
  • Test coverage: Coverage is appropriate for the reported alias ownership bug. I attempted ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.PushDownJoinOnAssertNumRowsTest, but it could not complete because this runner is missing thirdparty/installed/bin/protoc.
  • Observability, transaction, persistence, data writes, and memory tracking: Not applicable to this optimizer-only rewrite.
  • Nereids-specific checks: Join types remain restricted to inner/cross joins, no new stage/rule type is introduced, and the rewrite does not introduce an obvious rule-loop risk.

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

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 31538 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 2736d80dbf58dd7ec7c900b7fe250f9df99beda9, 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	17757	4035	4032	4032
q2	q3	10760	1399	804	804
q4	4686	478	345	345
q5	7620	2329	2086	2086
q6	237	170	134	134
q7	942	798	652	652
q8	9373	1762	1593	1593
q9	5127	4954	4947	4947
q10	6376	2219	1848	1848
q11	457	269	243	243
q12	624	420	300	300
q13	18170	3352	2773	2773
q14	268	259	236	236
q15	q16	828	794	713	713
q17	946	1009	1011	1009
q18	6790	5794	5532	5532
q19	1413	1227	1088	1088
q20	632	483	309	309
q21	6231	2819	2588	2588
q22	454	370	306	306
Total cold run time: 99691 ms
Total hot run time: 31538 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	4815	4787	4923	4787
q2	q3	4981	5256	4629	4629
q4	2129	2205	1384	1384
q5	5058	4717	4686	4686
q6	247	176	127	127
q7	1903	1749	1536	1536
q8	2436	2095	2137	2095
q9	8079	7520	7444	7444
q10	4758	4715	4251	4251
q11	553	382	356	356
q12	737	734	524	524
q13	3049	3345	2820	2820
q14	283	274	261	261
q15	q16	671	713	605	605
q17	1305	1257	1238	1238
q18	7336	6852	6805	6805
q19	1103	1112	1168	1112
q20	2215	2224	1955	1955
q21	5230	4541	4371	4371
q22	511	447	404	404
Total cold run time: 57399 ms
Total hot run time: 51390 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 171874 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 2736d80dbf58dd7ec7c900b7fe250f9df99beda9, data reload: false

query5	4336	655	516	516
query6	319	222	205	205
query7	4292	601	305	305
query8	332	236	217	217
query9	8798	4005	3996	3996
query10	502	333	290	290
query11	5774	2612	2265	2265
query12	182	129	122	122
query13	1303	580	436	436
query14	6074	5414	5083	5083
query14_1	4426	4436	4433	4433
query15	215	208	181	181
query16	1004	445	417	417
query17	948	721	602	602
query18	2446	491	356	356
query19	212	196	154	154
query20	134	129	128	128
query21	217	140	118	118
query22	13627	13581	13292	13292
query23	17463	16489	16202	16202
query23_1	16418	16397	16264	16264
query24	7584	1752	1332	1332
query24_1	1292	1299	1313	1299
query25	563	486	420	420
query26	1351	323	173	173
query27	2743	595	337	337
query28	4485	2031	2006	2006
query29	1020	638	500	500
query30	306	243	203	203
query31	1130	1087	949	949
query32	93	79	77	77
query33	552	376	316	316
query34	1187	1117	654	654
query35	790	799	708	708
query36	1396	1389	1239	1239
query37	155	108	93	93
query38	3226	3228	3070	3070
query39	934	930	892	892
query39_1	890	879	883	879
query40	262	150	131	131
query41	73	71	72	71
query42	117	120	114	114
query43	331	335	294	294
query44	
query45	214	213	210	210
query46	1133	1243	748	748
query47	2390	2442	2305	2305
query48	409	392	306	306
query49	648	522	401	401
query50	951	365	246	246
query51	4334	4398	4305	4305
query52	109	117	96	96
query53	262	291	220	220
query54	328	295	269	269
query55	97	93	87	87
query56	308	331	350	331
query57	1444	1441	1355	1355
query58	303	270	269	269
query59	1609	1700	1471	1471
query60	318	313	304	304
query61	163	158	161	158
query62	705	655	575	575
query63	242	201	201	201
query64	2410	818	640	640
query65	
query66	1749	484	350	350
query67	29895	29738	29603	29603
query68	
query69	474	338	310	310
query70	1033	957	1007	957
query71	314	277	269	269
query72	2997	2727	2472	2472
query73	860	762	431	431
query74	5121	4926	4828	4828
query75	2700	2608	2254	2254
query76	2307	1164	792	792
query77	418	406	339	339
query78	12425	12413	11874	11874
query79	1291	1065	715	715
query80	572	550	448	448
query81	450	278	244	244
query82	225	164	119	119
query83	278	271	250	250
query84	287	142	114	114
query85	862	538	483	483
query86	395	321	318	318
query87	3436	3367	3274	3274
query88	3617	2749	2735	2735
query89	434	393	341	341
query90	2153	187	177	177
query91	180	164	145	145
query92	78	76	73	73
query93	1388	1523	913	913
query94	550	357	343	343
query95	682	374	447	374
query96	1127	845	330	330
query97	2740	2724	2620	2620
query98	246	231	241	231
query99	1184	1145	1026	1026
Total cold run time: 253299 ms
Total hot run time: 171874 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 92.31% (24/26) 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 66.67% (18/27) 🎉
Increment coverage report
Complete coverage report

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: Remove an internal issue reference from the assert row join pushdown test comment and fix the illustrated plan tree indentation so it matches the expected rewrite shape.

### Release note

None

### Check List (For Author)

- Test: Manual test

    - Verified the diff with git diff --check and confirmed the internal issue reference no longer appears in the changed test file.

    - Attempted ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.PushDownJoinOnAssertNumRowsTest, but the FE build failed before executing the test because generated ImmutableFlightAuthResult references missing edu.umd.cs.findbugs.annotations.SuppressFBWarnings.

- Behavior changed: No

- Does this need documentation: No
@morrySnow
Copy link
Copy Markdown
Contributor Author

run buildall

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

Review result: no blocking issues found in the current patch.

Checkpoint conclusions:

  • Goal and tests: The change fixes PushDownJoinOnAssertNumRows slot ownership after pushing a top join condition through a project, and adds a focused unit test for the right-child alias case. The test command is documented by the author; I did not rerun it in this runner.
  • Scope: The implementation is small and focused on the affected rewrite, with helper extraction to preserve child ordering.
  • Concurrency/lifecycle/config/compatibility: Not applicable; this is a planner rewrite and test-only change, with no shared mutable runtime state, lifecycle management, configuration, protocol, or storage format changes.
  • Parallel code paths: The existing left-child and right-child pushdown branches now share assembly logic; I did not find another equivalent path needing the same fix.
  • Conditional checks: The new bottom-join output filtering is the right ownership test after project expression substitution, and the empty-slot guard avoids rewriting conditions that do not reference the bottom join.
  • Test coverage: The added unit test covers the reported right-child projected alias shape. Existing tests continue to cover left/right pushdown, project wrapping, cross join, multiple-condition rejection, outer-join rejection, and assert-project wrapping.
  • Observability/transaction/data writes/memory: Not applicable for this FE logical rewrite.
  • Performance: No material regression found; the added work is limited to existing expression slot inspection during rewrite.

Existing review threads: I verified the prior comments about internal issue reference removal and plan-tree indentation and did not duplicate them.

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

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 31565 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 148a195d166c0e2126b97c7f8e213c2b8d0cf9b9, 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	17696	4011	3977	3977
q2	q3	10809	1346	834	834
q4	4688	477	348	348
q5	7571	2235	2107	2107
q6	240	178	138	138
q7	927	786	640	640
q8	9396	1656	1599	1599
q9	5097	4925	4939	4925
q10	6374	2220	1901	1901
q11	437	273	252	252
q12	630	433	292	292
q13	18127	3350	2757	2757
q14	269	259	234	234
q15	q16	827	772	707	707
q17	997	916	926	916
q18	6955	5869	5513	5513
q19	1324	1229	1057	1057
q20	536	514	303	303
q21	6229	2867	2672	2672
q22	456	393	458	393
Total cold run time: 99585 ms
Total hot run time: 31565 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	4739	4877	4787	4787
q2	q3	4930	5272	4675	4675
q4	2101	2188	1400	1400
q5	5040	4748	4702	4702
q6	243	176	130	130
q7	1880	1741	1550	1550
q8	2413	2094	2127	2094
q9	7834	7424	7470	7424
q10	4778	4680	4236	4236
q11	537	394	355	355
q12	726	739	524	524
q13	3012	3367	2791	2791
q14	280	274	256	256
q15	q16	685	704	614	614
q17	1282	1252	1254	1252
q18	7353	6815	6803	6803
q19	1104	1150	1099	1099
q20	2223	2224	1940	1940
q21	5295	4643	4477	4477
q22	548	471	406	406
Total cold run time: 57003 ms
Total hot run time: 51515 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 171960 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 148a195d166c0e2126b97c7f8e213c2b8d0cf9b9, data reload: false

query5	4319	676	513	513
query6	347	234	212	212
query7	4340	620	319	319
query8	332	240	234	234
query9	8805	4129	4098	4098
query10	467	355	305	305
query11	5779	2523	2203	2203
query12	190	132	128	128
query13	1350	636	478	478
query14	6063	5454	5187	5187
query14_1	4512	4483	4425	4425
query15	215	210	188	188
query16	1009	473	454	454
query17	1130	756	628	628
query18	2490	517	367	367
query19	233	209	176	176
query20	146	132	132	132
query21	222	147	120	120
query22	13642	13562	13408	13408
query23	17316	16621	16190	16190
query23_1	16220	16340	16294	16294
query24	7518	1825	1312	1312
query24_1	1327	1355	1343	1343
query25	595	500	458	458
query26	1309	325	172	172
query27	2709	562	355	355
query28	4500	2023	2036	2023
query29	1027	654	525	525
query30	310	236	200	200
query31	1148	1097	966	966
query32	99	81	78	78
query33	570	377	361	361
query34	1189	1151	646	646
query35	786	792	705	705
query36	1414	1403	1223	1223
query37	157	111	91	91
query38	3207	3204	3058	3058
query39	927	923	915	915
query39_1	877	890	859	859
query40	228	151	122	122
query41	66	61	61	61
query42	114	109	106	106
query43	340	335	291	291
query44	
query45	215	208	208	208
query46	1102	1249	738	738
query47	2353	2341	2239	2239
query48	426	433	300	300
query49	634	500	389	389
query50	1005	360	259	259
query51	4347	4251	4241	4241
query52	109	105	95	95
query53	256	280	203	203
query54	319	269	251	251
query55	96	96	87	87
query56	291	314	317	314
query57	1457	1424	1341	1341
query58	325	279	268	268
query59	1633	1660	1487	1487
query60	320	326	304	304
query61	156	156	156	156
query62	710	659	598	598
query63	250	205	204	204
query64	2419	825	628	628
query65	
query66	1715	474	370	370
query67	29167	29701	29565	29565
query68	
query69	484	359	315	315
query70	1060	1002	1006	1002
query71	317	277	273	273
query72	3203	2918	2488	2488
query73	844	732	429	429
query74	5136	4996	4780	4780
query75	2709	2593	2257	2257
query76	2297	1173	815	815
query77	417	422	339	339
query78	12442	12410	12010	12010
query79	1520	1063	768	768
query80	683	539	452	452
query81	460	280	253	253
query82	2011	157	129	129
query83	365	275	258	258
query84	269	145	111	111
query85	911	540	457	457
query86	457	338	334	334
query87	3443	3375	3248	3248
query88	3691	2752	2761	2752
query89	449	398	349	349
query90	1978	188	186	186
query91	181	173	140	140
query92	87	80	74	74
query93	1566	1411	872	872
query94	668	368	314	314
query95	716	386	452	386
query96	1045	804	354	354
query97	2753	2749	2597	2597
query98	235	228	224	224
query99	1185	1153	1017	1017
Total cold run time: 255410 ms
Total hot run time: 171960 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 69.23% (18/26) 🎉
Increment coverage report
Complete coverage report

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

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. dev/4.1.x reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants