Skip to content

[fix](fe) Check all aggregate function arguments#65537

Open
morrySnow wants to merge 1 commit into
apache:masterfrom
morrySnow:fix-normalize-agg
Open

[fix](fe) Check all aggregate function arguments#65537
morrySnow wants to merge 1 commit into
apache:masterfrom
morrySnow:fix-normalize-agg

Conversation

@morrySnow

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: NormalizeAggregate only checked the first child of each aggregate function for nested aggregate functions. Aggregate functions in later arguments, such as SUM in the ORDER BY argument of GROUP_CONCAT, could bypass analysis validation. Check every aggregate child and add FE unit and regression coverage for the invalid query.

Release note

Reject nested aggregate functions in every aggregate function argument.

Check List (For Author)

  • Test: Unit Test and Regression test
    • Unit Test: NormalizeAggregateTest
    • Regression test: query_p0/aggregate/agg_group_concat
  • Behavior changed: Yes, invalid nested aggregate functions in non-first arguments are rejected during analysis
  • Does this need documentation: No

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: NormalizeAggregate only checked the first child of each aggregate function for nested aggregate functions. Aggregate functions in later arguments, such as SUM in the ORDER BY argument of GROUP_CONCAT, could bypass analysis validation. Check every aggregate child and add FE unit and regression coverage for the invalid query.

### Release note

Reject nested aggregate functions in every aggregate function argument.

### Check List (For Author)

- Test: Unit Test and Regression test
    - Unit Test: NormalizeAggregateTest
    - Regression test: query_p0/aggregate/agg_group_concat
- Behavior changed: Yes, invalid nested aggregate functions in non-first arguments are rejected during analysis
- 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

Copy link
Copy Markdown
Contributor Author

run buildall

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

I found one correctness issue in the aggregate-parameter validation.

Critical checkpoints:

  • Goal: the PR intends to reject aggregate functions nested in aggregate parameters. It covers the simple non-distinct group_concat(k order by sum(k)) case, but the validation still runs after some aggregate-containing children can be normalized to slots.
  • Scope/focus: the code change is small, but the affected normalization path has parallel distinct and pushdown-triggered order-key branches.
  • Concurrency/lifecycle/config/persistence/FE-BE protocol: not involved.
  • Parallel paths: issue found in distinct non-slot children and non-distinct order keys containing pushdown-triggering expressions.
  • Tests: the new FE and regression tests use the right expected-error pattern, but they only cover the simple non-distinct order-key case and miss the variants in the inline comment.
  • User focus: no additional user-provided focus was supplied.

Validation was static only. I did not run builds or tests because this review prompt forbids builds/code modifications, and this checkout is not worktree-initialized and lacks thirdparty/installed / thirdparty/installed/bin/protoc.

bottomSlotContext.normalizeToUseSlotRef(SessionVarGuardExpr.getExprWithGuard(aggFuncs));
if (normalizedAggFuncs.stream().anyMatch(agg -> !agg.children().isEmpty()
&& agg.child(0).containsType(AggregateFunction.class))) {
&& agg.children().stream().anyMatch(e -> e.containsType(AggregateFunction.class)))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This check still runs too late for children that were put into needPushDownSelfExprs. For example, group_concat(distinct k order by sum(k)) unwraps the order key in the distinct branch and maps sum(k) to a bottom-project alias slot before this block runs; similarly, count(distinct sum(k)) or an order key like sum(k) + row_number() over(...) can be replaced by a slot first. After normalizeToUseSlotRef, the aggregate child no longer contains an AggregateFunction, so this check misses the nested aggregate and may only fail later as an aggregate pushed into the wrong plan node. Please validate the original aggregate children/order-key children for non-window aggregate functions before any slot normalization, and add coverage for the distinct and pushdown-triggered variants.

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17605	4072	4018	4018
q2	2023	349	195	195
q3	10261	1405	815	815
q4	4684	464	336	336
q5	7634	845	569	569
q6	180	171	138	138
q7	778	831	618	618
q8	9327	1539	1487	1487
q9	5572	4364	4356	4356
q10	6765	1787	1537	1537
q11	496	363	308	308
q12	697	552	431	431
q13	18113	3355	2715	2715
q14	267	252	252	252
q15	q16	784	772	708	708
q17	983	974	1059	974
q18	7000	5601	5658	5601
q19	1328	1340	1045	1045
q20	797	635	547	547
q21	5992	2663	2344	2344
q22	432	356	299	299
Total cold run time: 101718 ms
Total hot run time: 29293 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4338	4283	4267	4267
q2	285	312	212	212
q3	4594	4937	4400	4400
q4	2030	2131	1386	1386
q5	4427	4350	4342	4342
q6	230	177	129	129
q7	1807	1596	2047	1596
q8	2657	2210	2184	2184
q9	8029	8166	7753	7753
q10	4722	4707	4268	4268
q11	556	420	376	376
q12	751	787	541	541
q13	3246	3640	2920	2920
q14	313	299	297	297
q15	q16	714	726	652	652
q17	1375	1325	1296	1296
q18	7959	7359	7364	7359
q19	1208	1116	1074	1074
q20	2205	2206	1923	1923
q21	5177	4534	4396	4396
q22	525	479	392	392
Total cold run time: 57148 ms
Total hot run time: 51763 ms

@hello-stephen

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

query5	4339	631	492	492
query6	472	211	204	204
query7	4878	611	328	328
query8	334	183	177	177
query9	8799	4032	3994	3994
query10	474	352	296	296
query11	5886	2339	2129	2129
query12	167	106	103	103
query13	1277	694	436	436
query14	6270	5315	4981	4981
query14_1	4283	4301	4274	4274
query15	214	210	187	187
query16	1036	475	460	460
query17	1140	732	590	590
query18	2479	477	355	355
query19	206	197	154	154
query20	118	112	107	107
query21	236	158	135	135
query22	13660	13576	13438	13438
query23	17538	16462	16159	16159
query23_1	16303	16234	16212	16212
query24	7633	1775	1264	1264
query24_1	1318	1313	1299	1299
query25	571	474	390	390
query26	1342	364	209	209
query27	2568	623	378	378
query28	4426	2037	2002	2002
query29	1136	629	530	530
query30	347	261	230	230
query31	1115	1088	982	982
query32	118	66	64	64
query33	543	328	264	264
query34	1205	1138	639	639
query35	765	795	679	679
query36	1408	1419	1261	1261
query37	202	106	91	91
query38	1849	1685	1627	1627
query39	918	901	903	901
query39_1	873	911	903	903
query40	241	161	142	142
query41	66	66	62	62
query42	95	90	94	90
query43	317	314	273	273
query44	1396	773	765	765
query45	199	193	186	186
query46	1055	1179	699	699
query47	2410	2366	2232	2232
query48	411	407	293	293
query49	574	416	320	320
query50	1045	421	314	314
query51	10787	10893	10626	10626
query52	85	84	73	73
query53	250	278	192	192
query54	296	232	211	211
query55	74	72	64	64
query56	272	287	277	277
query57	1438	1423	1353	1353
query58	275	257	246	246
query59	1547	1651	1419	1419
query60	309	265	249	249
query61	148	148	147	147
query62	714	649	580	580
query63	240	202	202	202
query64	2791	1042	857	857
query65	4862	4794	5117	4794
query66	1814	529	411	411
query67	29558	29357	29782	29357
query68	3254	1584	960	960
query69	408	303	254	254
query70	1090	993	960	960
query71	344	319	325	319
query72	3058	2736	2389	2389
query73	828	745	441	441
query74	5111	4940	4761	4761
query75	2618	2584	2238	2238
query76	2356	1170	755	755
query77	363	370	283	283
query78	12350	12451	11748	11748
query79	1404	1204	783	783
query80	1291	527	451	451
query81	547	327	284	284
query82	810	157	121	121
query83	372	318	331	318
query84	282	159	127	127
query85	957	593	510	510
query86	433	287	283	283
query87	1825	1824	1760	1760
query88	3666	2758	2777	2758
query89	451	407	352	352
query90	1930	202	195	195
query91	199	189	158	158
query92	66	62	56	56
query93	1567	1560	1061	1061
query94	738	354	315	315
query95	774	477	555	477
query96	1012	810	325	325
query97	2694	2702	2521	2521
query98	209	212	200	200
query99	1150	1180	1027	1027
Total cold run time: 266245 ms
Total hot run time: 180871 ms

@hello-stephen

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

query1	0.01	0.01	0.00
query2	0.10	0.04	0.05
query3	0.26	0.15	0.14
query4	1.61	0.15	0.15
query5	0.26	0.23	0.22
query6	1.28	1.08	1.09
query7	0.04	0.00	0.01
query8	0.06	0.04	0.04
query9	0.38	0.30	0.31
query10	0.58	0.55	0.54
query11	0.20	0.14	0.14
query12	0.18	0.14	0.14
query13	0.47	0.48	0.47
query14	1.01	0.98	1.01
query15	0.61	0.59	0.59
query16	0.32	0.34	0.31
query17	1.10	1.08	1.14
query18	0.22	0.21	0.21
query19	2.01	1.96	1.97
query20	0.02	0.01	0.01
query21	15.44	0.21	0.13
query22	4.84	0.05	0.05
query23	16.23	0.32	0.11
query24	3.05	0.43	0.34
query25	0.11	0.05	0.04
query26	0.72	0.20	0.15
query27	0.04	0.03	0.04
query28	3.52	0.92	0.52
query29	12.50	4.15	3.29
query30	0.28	0.15	0.15
query31	2.78	0.58	0.31
query32	3.23	0.59	0.48
query33	3.15	3.22	3.25
query34	15.56	4.26	3.51
query35	3.48	3.52	3.50
query36	0.55	0.44	0.42
query37	0.09	0.07	0.06
query38	0.05	0.04	0.04
query39	0.04	0.03	0.03
query40	0.18	0.17	0.17
query41	0.08	0.04	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 96.72 s
Total hot run time: 25.04 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

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

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 10.00% (1/10) 🎉
Increment coverage report
Complete coverage report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants