Skip to content

[fix](agg) Fix grouping function handling and repeatSlotIdList calculation in DecomposeRepeatWithPreAggregation#60091

Merged
morrySnow merged 4 commits into
apache:masterfrom
feiniaofeiafei:fix_repeat_rewrite
Feb 10, 2026
Merged

[fix](agg) Fix grouping function handling and repeatSlotIdList calculation in DecomposeRepeatWithPreAggregation#60091
morrySnow merged 4 commits into
apache:masterfrom
feiniaofeiafei:fix_repeat_rewrite

Conversation

@feiniaofeiafei

@feiniaofeiafei feiniaofeiafei commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Related PR: #59116 #60045

Problem Summary:
There are 2 problems:

  1. When DecomposeRepeatWithPreAggregation optimization removes the maximum grouping set, grouping functions (e.g., grouping(), grouping_id()) that reference expressions only existing in the removed grouping set would fail because of index lookup failure: When computing grouping function values, GroupingSetShapes.indexOf() would return -1 for expressions not in flattenGroupingSetExpression, causing incorrect behavior.

Example scenario:

SELECT a, b, c, grouping(c) 
FROM t1 
GROUP BY GROUPING SETS ((a, b, c), (a, b), (a), ());

After optimization removes the maximum grouping set (a, b, c), the expression c no longer exists in the remaining grouping sets. When computing grouping(c), the index lookup would fail.
2. The repeatSlotIdList calculation was incorrect because it relied on the assumption that the order of physicalRepeat.getOutputExpressions() matches the order of outputTuple. However, this assumption can be broken during rule rewriting (e.g., in DecomposeRepeatWithPreAggregation.constructRepeat() at line 502-503, where replacedRepeatOutputs is constructed by new ArrayList<>(child.getOutput()) and then appends grouping functions, potentially changing the order). This mismatch causes incorrect slot ID mapping and wrong query results.

Example scenario:
When DecomposeRepeatWithPreAggregation rewrites a repeat plan, the output expressions order may differ from the output tuple order, leading to incorrect slot ID mapping in repeatSlotIdList.

Solution:

  1. For problem 1: Modified Repeat.toShapes() method to ensure all expressions referenced by grouping functions are included in flattenGroupingSetExpression, even if they are not in any grouping set. For expressions that only exist in the removed maximum grouping set, they are correctly marked as shouldBeErasedToNull = true in all remaining grouping sets, which is the correct SQL semantics.

Key changes:

  • Repeat.toShapes(): Enhanced to collect all expressions referenced by grouping functions using ExpressionUtils.collectToList() and merge them into flattenGroupingSetExpression
  • For expressions not in any grouping set, they are correctly marked as shouldBeErasedToNull = true in all GroupingSetShape instances
  • This ensures GroupingSetShapes.indexOf() always returns a valid index for grouping function arguments, preventing index lookup failures
  1. For problem 2: Modified Repeat.computeRepeatSlotIdList() method to accept an additional outputSlots parameter. Instead of relying on the order of outputExpressions matching outputTuple, the method now uses outputSlots to correctly map grouping set expressions to their indices in the output tuple. This ensures correct slot ID calculation even when rule rewriting changes the order of output expressions.

Key changes:

  • computeRepeatSlotIdList(List<Integer> slotIdList, List<Slot> outputSlots): Added outputSlots parameter
  • getGroupingSetsIndexesInOutput(List<Slot> outputSlots): Modified to use outputSlots instead of getOutputExpressions()
  • indexesOfOutput(List<Slot> outputSlots): Modified to build index map from outputSlots instead of getOutputExpressions()
  • PhysicalPlanTranslator.visitPhysicalRepeat(): Updated to pass outputSlots to computeRepeatSlotIdList()
  1. Another task for this pull request is to set the shuffle key for the rewritten bottom aggregation. Choosing a suitable shuffle key can improve the aggregation rate of the top aggregation's local aggregation.

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

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

@feiniaofeiafei

Copy link
Copy Markdown
Contributor Author

run buildall

@doris-robot

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

------ Round 1 ----------------------------------
q1	17632	4102	4048	4048
q2	2027	388	234	234
q3	10127	1252	712	712
q4	10189	761	297	297
q5	7517	2069	1881	1881
q6	182	167	135	135
q7	953	786	648	648
q8	9276	1443	1151	1151
q9	4957	4631	4565	4565
q10	6714	1779	1392	1392
q11	523	300	275	275
q12	668	733	612	612
q13	17805	3838	3084	3084
q14	284	302	286	286
q15	591	510	505	505
q16	682	687	647	647
q17	631	771	491	491
q18	6714	6516	6860	6516
q19	1163	1023	686	686
q20	411	374	259	259
q21	3246	2623	2390	2390
q22	1141	1076	1043	1043
Total cold run time: 103433 ms
Total hot run time: 31857 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4314	4384	4317	4317
q2	337	416	328	328
q3	2232	2791	2432	2432
q4	1403	1890	1453	1453
q5	4474	4293	4529	4293
q6	213	174	125	125
q7	1943	1907	1796	1796
q8	2528	2378	2488	2378
q9	7232	7081	7160	7081
q10	2536	2776	2229	2229
q11	551	478	487	478
q12	715	754	682	682
q13	3620	4075	3223	3223
q14	264	277	271	271
q15	528	485	482	482
q16	632	661	610	610
q17	1097	1229	1343	1229
q18	7608	7325	7293	7293
q19	800	775	775	775
q20	1885	1950	1789	1789
q21	4557	4293	4158	4158
q22	1093	1006	989	989
Total cold run time: 50562 ms
Total hot run time: 48411 ms

@doris-robot

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

query5	4860	625	494	494
query6	341	240	221	221
query7	4214	461	266	266
query8	354	258	255	255
query9	8798	2889	2887	2887
query10	550	381	345	345
query11	15250	15303	14915	14915
query12	200	120	119	119
query13	1264	486	386	386
query14	7162	3056	2732	2732
query14_1	2649	2645	2671	2645
query15	196	193	166	166
query16	975	472	469	469
query17	1084	633	540	540
query18	2684	414	327	327
query19	214	216	188	188
query20	122	114	111	111
query21	215	140	116	116
query22	4063	3970	4017	3970
query23	16410	15695	15398	15398
query23_1	15416	15512	15459	15459
query24	6938	1525	1147	1147
query24_1	1138	1164	1151	1151
query25	500	431	373	373
query26	1231	260	146	146
query27	2764	439	281	281
query28	4534	2159	2159	2159
query29	734	531	420	420
query30	312	241	206	206
query31	804	616	582	582
query32	90	76	73	73
query33	529	357	318	318
query34	915	878	541	541
query35	715	761	689	689
query36	896	898	853	853
query37	139	98	86	86
query38	2737	2752	2683	2683
query39	772	755	729	729
query39_1	709	713	731	713
query40	220	139	118	118
query41	66	62	60	60
query42	106	100	110	100
query43	420	440	458	440
query44	1316	743	743	743
query45	187	195	189	189
query46	829	937	570	570
query47	1403	1498	1420	1420
query48	325	320	240	240
query49	608	436	341	341
query50	615	272	202	202
query51	3771	3867	3806	3806
query52	102	108	96	96
query53	284	324	272	272
query54	288	289	275	275
query55	82	87	78	78
query56	313	302	309	302
query57	1049	1002	968	968
query58	267	252	255	252
query59	1993	2204	2058	2058
query60	340	333	318	318
query61	149	146	143	143
query62	393	344	309	309
query63	289	264	269	264
query64	4785	1269	957	957
query65	3841	3712	3735	3712
query66	1395	424	314	314
query67	15593	15599	15372	15372
query68	2408	1090	757	757
query69	450	363	327	327
query70	996	948	918	918
query71	317	311	290	290
query72	5299	3176	3335	3176
query73	610	721	313	313
query74	8730	8780	8545	8545
query75	2753	2810	2494	2494
query76	2293	1059	672	672
query77	366	379	308	308
query78	9706	9921	9148	9148
query79	1063	906	581	581
query80	672	584	525	525
query81	493	266	237	237
query82	1330	149	116	116
query83	380	260	253	253
query84	261	127	105	105
query85	901	542	496	496
query86	362	298	287	287
query87	2834	2861	2754	2754
query88	3531	2610	2574	2574
query89	403	363	326	326
query90	1893	181	169	169
query91	183	211	136	136
query92	82	69	69	69
query93	915	918	537	537
query94	454	323	281	281
query95	573	397	328	328
query96	653	500	232	232
query97	2328	2382	2304	2304
query98	228	211	204	204
query99	615	575	524	524
Total cold run time: 248461 ms
Total hot run time: 174145 ms

@doris-robot

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

query1	0.06	0.05	0.04
query2	0.10	0.05	0.04
query3	0.26	0.09	0.08
query4	1.62	0.12	0.11
query5	0.28	0.25	0.24
query6	1.15	0.67	0.64
query7	0.04	0.03	0.02
query8	0.05	0.04	0.04
query9	0.57	0.50	0.51
query10	0.55	0.54	0.55
query11	0.14	0.10	0.10
query12	0.15	0.11	0.10
query13	0.59	0.58	0.58
query14	0.93	0.96	0.95
query15	0.79	0.78	0.79
query16	0.39	0.40	0.38
query17	1.01	1.07	1.01
query18	0.23	0.21	0.21
query19	1.93	1.84	1.90
query20	0.02	0.02	0.01
query21	15.48	0.23	0.15
query22	5.43	0.06	0.04
query23	15.99	0.27	0.11
query24	1.50	0.25	0.32
query25	0.12	0.07	0.04
query26	0.14	0.14	0.13
query27	0.06	0.08	0.06
query28	3.26	1.10	0.88
query29	12.52	3.93	3.15
query30	0.27	0.13	0.12
query31	2.82	0.65	0.38
query32	3.24	0.57	0.46
query33	3.02	3.06	3.10
query34	16.44	5.10	4.49
query35	4.45	4.44	4.50
query36	0.64	0.50	0.49
query37	0.11	0.07	0.07
query38	0.07	0.04	0.04
query39	0.05	0.03	0.03
query40	0.16	0.14	0.14
query41	0.09	0.03	0.03
query42	0.05	0.03	0.03
query43	0.04	0.04	0.04
Total cold run time: 96.81 s
Total hot run time: 26.84 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 80.00% (16/20) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

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

@feiniaofeiafei

Copy link
Copy Markdown
Contributor Author

run buildall

@doris-robot

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

------ Round 1 ----------------------------------
q1	17614	4788	4589	4589
q2	2030	325	188	188
q3	10218	1278	738	738
q4	10199	814	301	301
q5	7494	2121	1798	1798
q6	186	169	137	137
q7	955	705	587	587
q8	9293	1457	1102	1102
q9	4805	4555	4618	4555
q10	6741	1659	1277	1277
q11	533	302	285	285
q12	337	391	232	232
q13	17787	3838	3090	3090
q14	239	231	221	221
q15	583	521	524	521
q16	654	630	590	590
q17	646	805	498	498
q18	6780	6464	6336	6336
q19	1093	969	624	624
q20	397	351	229	229
q21	2658	1969	1876	1876
q22	1025	996	954	954
Total cold run time: 102267 ms
Total hot run time: 30728 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4749	4719	4678	4678
q2	323	410	335	335
q3	2121	2665	2304	2304
q4	1346	1771	1313	1313
q5	4105	3969	3997	3969
q6	208	170	130	130
q7	1889	1848	1728	1728
q8	2828	2525	2523	2523
q9	7246	7299	7179	7179
q10	2510	2824	2368	2368
q11	579	474	483	474
q12	703	728	655	655
q13	3593	4125	3418	3418
q14	293	326	311	311
q15	562	517	518	517
q16	645	691	663	663
q17	1134	1260	1297	1260
q18	8279	7961	7918	7918
q19	882	832	845	832
q20	2040	2127	1942	1942
q21	4865	4478	4468	4468
q22	1108	1095	1100	1095
Total cold run time: 52008 ms
Total hot run time: 50080 ms

@doris-robot

Copy link
Copy Markdown
TPC-DS: Total hot run time: 173968 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 43a94541c6ec2325f1bef1dbe989761f8da5f8b1, data reload: false

query5	4410	673	504	504
query6	332	219	200	200
query7	4219	451	247	247
query8	342	247	236	236
query9	8737	2878	2876	2876
query10	460	325	322	322
query11	15341	15217	16004	15217
query12	204	127	129	127
query13	1309	480	365	365
query14	5618	3137	2996	2996
query14_1	2876	2826	2777	2777
query15	209	199	181	181
query16	1035	498	464	464
query17	909	683	606	606
query18	2469	413	341	341
query19	204	190	150	150
query20	125	119	117	117
query21	214	132	116	116
query22	4077	4285	4052	4052
query23	16169	15492	15498	15492
query23_1	15391	15303	15455	15303
query24	7211	1518	1145	1145
query24_1	1190	1145	1153	1145
query25	540	448	413	413
query26	1239	262	151	151
query27	2780	432	276	276
query28	4597	2161	2160	2160
query29	791	544	443	443
query30	310	233	201	201
query31	752	620	551	551
query32	83	77	72	72
query33	552	354	313	313
query34	918	882	534	534
query35	737	738	680	680
query36	883	854	823	823
query37	139	97	87	87
query38	2705	2680	2675	2675
query39	774	763	747	747
query39_1	710	697	711	697
query40	220	138	117	117
query41	70	65	61	61
query42	97	91	96	91
query43	439	426	390	390
query44	1340	752	749	749
query45	195	188	178	178
query46	815	953	581	581
query47	1464	1444	1397	1397
query48	319	342	262	262
query49	630	440	356	356
query50	672	280	204	204
query51	3730	3793	3752	3752
query52	94	94	80	80
query53	212	223	175	175
query54	297	270	259	259
query55	86	84	82	82
query56	310	340	316	316
query57	1079	1062	875	875
query58	274	265	244	244
query59	2077	2085	2080	2080
query60	324	320	313	313
query61	150	141	148	141
query62	414	343	304	304
query63	200	161	161	161
query64	4939	1136	855	855
query65	3818	3758	3786	3758
query66	1450	410	314	314
query67	15645	15671	15501	15501
query68	2441	1072	729	729
query69	397	314	273	273
query70	1015	930	948	930
query71	313	292	278	278
query72	5351	3130	3251	3130
query73	579	721	315	315
query74	8711	8858	8568	8568
query75	2278	2286	1910	1910
query76	2260	1061	648	648
query77	342	377	304	304
query78	9796	10038	9205	9205
query79	2349	905	584	584
query80	1750	517	443	443
query81	557	262	228	228
query82	1250	148	130	130
query83	340	259	243	243
query84	303	122	100	100
query85	874	476	407	407
query86	413	299	281	281
query87	2829	2913	2772	2772
query88	3461	2591	2533	2533
query89	307	255	244	244
query90	1997	166	160	160
query91	168	159	135	135
query92	79	75	71	71
query93	1504	998	674	674
query94	644	312	285	285
query95	587	389	312	312
query96	632	494	229	229
query97	2324	2362	2303	2303
query98	234	202	196	196
query99	625	592	505	505
Total cold run time: 248861 ms
Total hot run time: 173968 ms

@doris-robot

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

query1	0.06	0.05	0.05
query2	0.09	0.04	0.04
query3	0.25	0.09	0.08
query4	1.61	0.12	0.11
query5	0.27	0.25	0.26
query6	1.15	0.67	0.65
query7	0.04	0.03	0.02
query8	0.05	0.03	0.04
query9	0.58	0.50	0.50
query10	0.56	0.54	0.55
query11	0.14	0.09	0.10
query12	0.15	0.11	0.11
query13	0.60	0.59	0.59
query14	0.94	0.96	0.94
query15	0.78	0.77	0.80
query16	0.37	0.39	0.40
query17	1.08	1.08	1.07
query18	0.23	0.21	0.20
query19	2.04	1.87	1.93
query20	0.02	0.01	0.01
query21	15.44	0.27	0.14
query22	4.91	0.05	0.04
query23	15.74	0.29	0.10
query24	2.48	0.32	1.07
query25	0.07	0.05	0.05
query26	0.14	0.13	0.12
query27	0.07	0.05	0.06
query28	5.06	1.06	0.89
query29	12.52	3.91	3.12
query30	0.29	0.14	0.11
query31	2.82	0.64	0.38
query32	3.23	0.56	0.45
query33	3.01	3.00	3.05
query34	15.92	5.10	4.42
query35	4.45	4.49	4.49
query36	0.65	0.50	0.49
query37	0.12	0.06	0.07
query38	0.07	0.04	0.04
query39	0.04	0.03	0.04
query40	0.16	0.13	0.13
query41	0.09	0.04	0.03
query42	0.05	0.03	0.03
query43	0.05	0.04	0.03
Total cold run time: 98.39 s
Total hot run time: 26.83 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 75.00% (6/8) 🎉
Increment coverage report
Complete coverage report

@feiniaofeiafei

Copy link
Copy Markdown
Contributor Author

run buildall

1 similar comment
@feiniaofeiafei

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 81.82% (18/22) 🎉
Increment coverage report
Complete coverage report

@doris-robot

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

------ Round 1 ----------------------------------
q1	17663	4708	4564	4564
q2	1994	307	215	215
q3	10246	1327	758	758
q4	10231	883	312	312
q5	8079	2067	1882	1882
q6	236	170	136	136
q7	898	693	590	590
q8	9272	1435	1044	1044
q9	4938	4547	4691	4547
q10	6843	1705	1269	1269
q11	502	300	263	263
q12	373	366	215	215
q13	17788	3824	3029	3029
q14	254	237	210	210
q15	650	516	526	516
q16	667	656	586	586
q17	739	781	505	505
q18	6782	6254	6796	6254
q19	1581	1044	665	665
q20	434	355	244	244
q21	2952	2268	2105	2105
q22	1142	1084	1030	1030
Total cold run time: 104264 ms
Total hot run time: 30939 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5136	4979	4931	4931
q2	338	397	346	346
q3	2354	2946	2566	2566
q4	1416	1894	1401	1401
q5	4480	4430	4251	4251
q6	215	195	130	130
q7	2257	1929	1818	1818
q8	2578	2448	2342	2342
q9	7238	7262	7241	7241
q10	2480	2850	2303	2303
q11	538	485	449	449
q12	707	800	630	630
q13	3601	3784	3106	3106
q14	270	285	257	257
q15	536	491	501	491
q16	614	655	617	617
q17	1111	1274	1347	1274
q18	7583	7305	7113	7113
q19	826	777	787	777
q20	1902	1984	1849	1849
q21	4529	4311	4085	4085
q22	1076	1038	978	978
Total cold run time: 51785 ms
Total hot run time: 48955 ms

@doris-robot

Copy link
Copy Markdown
TPC-DS: Total hot run time: 173439 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 8b4c9510229ae3641152b528cdb62e3dfdc2e650, data reload: false

query5	4438	651	491	491
query6	330	230	210	210
query7	4215	464	267	267
query8	348	252	237	237
query9	8703	2850	2839	2839
query10	463	322	286	286
query11	15233	15078	15041	15041
query12	178	115	115	115
query13	1238	460	374	374
query14	5558	2972	2706	2706
query14_1	2633	2547	2571	2547
query15	211	189	167	167
query16	968	476	481	476
query17	982	652	548	548
query18	2412	429	332	332
query19	194	178	150	150
query20	122	114	112	112
query21	208	159	113	113
query22	4213	4340	4173	4173
query23	16170	15742	15563	15563
query23_1	15555	15531	15547	15531
query24	7088	1552	1181	1181
query24_1	1145	1146	1162	1146
query25	511	438	385	385
query26	1242	287	146	146
query27	2747	440	268	268
query28	4595	2151	2134	2134
query29	732	517	413	413
query30	301	239	201	201
query31	807	617	553	553
query32	85	77	75	75
query33	540	349	305	305
query34	901	867	541	541
query35	701	759	665	665
query36	889	900	843	843
query37	165	96	86	86
query38	2704	2800	2665	2665
query39	775	746	732	732
query39_1	722	716	730	716
query40	220	131	113	113
query41	71	62	62	62
query42	97	94	91	91
query43	456	481	412	412
query44	1323	747	743	743
query45	186	184	172	172
query46	817	945	573	573
query47	1475	1448	1402	1402
query48	323	327	233	233
query49	604	441	353	353
query50	667	262	214	214
query51	3766	3801	3760	3760
query52	92	91	87	87
query53	217	224	163	163
query54	281	251	252	251
query55	85	77	74	74
query56	299	315	310	310
query57	1016	1027	962	962
query58	270	257	252	252
query59	2054	2107	2176	2107
query60	322	339	325	325
query61	146	150	139	139
query62	422	350	307	307
query63	187	161	163	161
query64	4934	1238	915	915
query65	3759	3746	3737	3737
query66	1480	435	327	327
query67	15619	15507	15407	15407
query68	2477	1043	709	709
query69	415	312	325	312
query70	1005	930	860	860
query71	292	275	269	269
query72	5238	3156	3192	3156
query73	598	717	307	307
query74	8670	8684	8522	8522
query75	2297	2299	1884	1884
query76	2258	1034	683	683
query77	352	375	312	312
query78	9705	9837	9222	9222
query79	1112	927	569	569
query80	620	536	422	422
query81	471	261	231	231
query82	1381	151	122	122
query83	367	265	247	247
query84	280	126	91	91
query85	848	467	413	413
query86	355	296	295	295
query87	2847	2819	2731	2731
query88	3495	2574	2550	2550
query89	299	252	239	239
query90	1903	173	167	167
query91	170	151	134	134
query92	77	72	71	71
query93	1074	1019	647	647
query94	463	313	292	292
query95	568	328	333	328
query96	646	501	230	230
query97	2348	2398	2322	2322
query98	222	203	200	200
query99	596	567	504	504
Total cold run time: 245134 ms
Total hot run time: 173439 ms

@doris-robot

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

query1	0.05	0.04	0.05
query2	0.10	0.05	0.05
query3	0.26	0.08	0.08
query4	1.61	0.12	0.12
query5	0.29	0.25	0.25
query6	1.15	0.65	0.64
query7	0.03	0.02	0.03
query8	0.05	0.04	0.04
query9	0.57	0.50	0.50
query10	0.54	0.55	0.55
query11	0.14	0.10	0.10
query12	0.14	0.11	0.11
query13	0.61	0.58	0.59
query14	0.95	0.93	0.96
query15	0.79	0.78	0.80
query16	0.42	0.39	0.38
query17	1.04	1.09	1.06
query18	0.24	0.22	0.21
query19	1.84	1.87	1.74
query20	0.02	0.01	0.02
query21	15.43	0.29	0.14
query22	5.04	0.04	0.04
query23	15.81	0.28	0.11
query24	1.05	0.66	0.80
query25	0.11	0.19	0.14
query26	0.14	0.14	0.13
query27	0.09	0.06	0.05
query28	5.36	1.07	0.89
query29	12.52	3.93	3.16
query30	0.27	0.13	0.11
query31	2.81	0.63	0.39
query32	3.23	0.57	0.45
query33	3.05	2.98	3.01
query34	16.01	5.14	4.44
query35	4.46	4.48	4.46
query36	0.69	0.51	0.49
query37	0.11	0.07	0.07
query38	0.07	0.04	0.03
query39	0.05	0.03	0.02
query40	0.16	0.14	0.13
query41	0.09	0.04	0.03
query42	0.04	0.02	0.02
query43	0.05	0.04	0.03
Total cold run time: 97.48 s
Total hot run time: 27.16 s

@feiniaofeiafei

Copy link
Copy Markdown
Contributor Author

run cloud_p0

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 90.91% (20/22) 🎉
Increment coverage report
Complete coverage report

1 similar comment
@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 90.91% (20/22) 🎉
Increment coverage report
Complete coverage report

@feiniaofeiafei

Copy link
Copy Markdown
Contributor Author

run buildall

@feiniaofeiafei feiniaofeiafei changed the title [fix](agg) Not rewrite when grouping scalar function reference expressions that only exist in the largest grouping set [fix](agg) Fix grouping function handling and repeatSlotIdList calculation in DecomposeRepeatWithPreAggregation Jan 27, 2026
@doris-robot

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

------ Round 1 ----------------------------------
q1	17651	5220	5004	5004
q2	2108	303	194	194
q3	10173	1271	749	749
q4	10209	830	310	310
q5	7535	2138	1925	1925
q6	196	179	151	151
q7	859	720	599	599
q8	9267	1403	1170	1170
q9	5159	4748	4771	4748
q10	6812	1935	1544	1544
q11	523	291	283	283
q12	335	375	226	226
q13	17774	4075	3197	3197
q14	232	249	221	221
q15	905	836	807	807
q16	670	675	632	632
q17	637	775	517	517
q18	6658	6469	6311	6311
q19	1230	994	622	622
q20	403	363	242	242
q21	2644	2070	1892	1892
q22	1033	999	966	966
Total cold run time: 103013 ms
Total hot run time: 32310 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5318	5279	5293	5279
q2	269	326	244	244
q3	2169	2657	2245	2245
q4	1353	1725	1305	1305
q5	4309	4207	4238	4207
q6	218	184	143	143
q7	2408	2088	1855	1855
q8	2571	2454	2442	2442
q9	7603	7680	7616	7616
q10	2859	3134	2786	2786
q11	555	482	460	460
q12	697	736	639	639
q13	4045	4559	3679	3679
q14	318	348	339	339
q15	891	870	897	870
q16	696	803	751	751
q17	1173	1336	1646	1336
q18	8059	8248	7834	7834
q19	901	860	868	860
q20	2083	2155	1993	1993
q21	4501	4205	4122	4122
q22	1060	1024	990	990
Total cold run time: 54056 ms
Total hot run time: 51995 ms

@doris-robot

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

query1	0.05	0.04	0.04
query2	0.09	0.05	0.04
query3	0.26	0.09	0.08
query4	1.62	0.11	0.10
query5	0.27	0.24	0.24
query6	1.17	0.68	0.67
query7	0.04	0.03	0.03
query8	0.06	0.04	0.05
query9	0.56	0.51	0.50
query10	0.54	0.54	0.55
query11	0.15	0.10	0.10
query12	0.15	0.10	0.11
query13	0.63	0.62	0.63
query14	1.08	1.07	1.05
query15	0.87	0.87	0.86
query16	0.42	0.39	0.42
query17	1.11	1.11	1.13
query18	0.23	0.21	0.22
query19	2.01	2.03	1.98
query20	0.02	0.01	0.02
query21	15.42	0.26	0.14
query22	4.89	0.05	0.05
query23	15.73	0.29	0.11
query24	1.07	0.60	0.59
query25	0.08	0.06	0.11
query26	0.14	0.14	0.14
query27	0.07	0.07	0.05
query28	3.90	1.15	0.95
query29	12.55	3.97	3.16
query30	0.28	0.13	0.12
query31	2.82	0.64	0.40
query32	3.24	0.59	0.49
query33	3.24	3.26	3.25
query34	16.47	5.38	4.72
query35	4.73	4.77	4.78
query36	0.64	0.49	0.49
query37	0.11	0.07	0.06
query38	0.07	0.04	0.04
query39	0.04	0.03	0.03
query40	0.19	0.17	0.15
query41	0.09	0.03	0.04
query42	0.05	0.03	0.03
query43	0.05	0.03	0.03
Total cold run time: 97.2 s
Total hot run time: 28.57 s

@feiniaofeiafei

Copy link
Copy Markdown
Contributor Author

run p0

@feiniaofeiafei

Copy link
Copy Markdown
Contributor Author

run cloud_p0

@feiniaofeiafei

Copy link
Copy Markdown
Contributor Author

run feut

@feiniaofeiafei

Copy link
Copy Markdown
Contributor Author

run p0

@feiniaofeiafei

Copy link
Copy Markdown
Contributor Author

run buildall

@doris-robot

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

------ Round 1 ----------------------------------
q1	17650	4472	4277	4277
q2	2014	358	238	238
q3	10169	1276	742	742
q4	10195	772	306	306
q5	7494	2218	1893	1893
q6	200	176	143	143
q7	878	722	599	599
q8	9266	1356	1124	1124
q9	4687	4582	4550	4550
q10	6824	1930	1541	1541
q11	518	313	310	310
q12	327	368	230	230
q13	17792	4042	3220	3220
q14	236	240	215	215
q15	879	798	813	798
q16	671	673	623	623
q17	684	815	518	518
q18	6475	5817	6005	5817
q19	1281	1028	703	703
q20	583	556	392	392
q21	2708	1922	1974	1922
q22	367	341	282	282
Total cold run time: 101898 ms
Total hot run time: 30443 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4669	4547	4668	4547
q2	259	357	268	268
q3	2356	2967	2441	2441
q4	1477	1909	1446	1446
q5	4605	4787	4666	4666
q6	234	181	151	151
q7	1979	1909	1820	1820
q8	2925	2466	2444	2444
q9	7511	7646	7554	7554
q10	2996	3154	2698	2698
q11	553	480	457	457
q12	669	732	611	611
q13	3915	4152	3223	3223
q14	262	284	266	266
q15	824	770	776	770
q16	636	681	632	632
q17	1071	1327	1294	1294
q18	7486	7472	7590	7472
q19	827	772	774	772
q20	1923	2038	1852	1852
q21	4514	4287	4077	4077
q22	579	520	509	509
Total cold run time: 52270 ms
Total hot run time: 49970 ms

@doris-robot

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

query5	4331	602	484	484
query6	331	218	212	212
query7	4202	463	271	271
query8	332	255	248	248
query9	8719	2757	2765	2757
query10	507	404	343	343
query11	16754	16510	16119	16119
query12	186	122	143	122
query13	1264	453	361	361
query14	6335	3235	2979	2979
query14_1	2844	2812	2779	2779
query15	202	192	173	173
query16	979	462	441	441
query17	1100	688	594	594
query18	2509	428	334	334
query19	213	199	174	174
query20	131	125	119	119
query21	216	146	124	124
query22	5002	4985	5011	4985
query23	19071	18640	18233	18233
query23_1	18383	18399	18316	18316
query24	7146	1579	1197	1197
query24_1	1192	1191	1224	1191
query25	505	420	380	380
query26	1228	275	154	154
query27	2767	458	292	292
query28	4481	1888	1882	1882
query29	772	530	444	444
query30	317	256	216	216
query31	869	738	646	646
query32	85	74	75	74
query33	514	328	283	283
query34	903	903	557	557
query35	642	683	607	607
query36	1111	1135	1007	1007
query37	135	107	88	88
query38	2973	2912	2848	2848
query39	947	919	904	904
query39_1	891	888	888	888
query40	218	134	119	119
query41	65	62	62	62
query42	103	100	100	100
query43	416	457	376	376
query44	1309	734	712	712
query45	197	192	179	179
query46	883	980	610	610
query47	2154	2159	2101	2101
query48	314	303	224	224
query49	598	429	350	350
query50	677	269	197	197
query51	4102	4115	4043	4043
query52	105	102	95	95
query53	291	334	269	269
query54	290	267	251	251
query55	89	87	82	82
query56	310	304	321	304
query57	1364	1354	1256	1256
query58	269	255	258	255
query59	1977	2212	2036	2036
query60	340	340	317	317
query61	148	153	145	145
query62	587	582	505	505
query63	300	275	273	273
query64	4766	1216	921	921
query65	4547	4400	4448	4400
query66	1428	446	346	346
query67	16190	16302	16238	16238
query68	2415	1065	713	713
query69	404	311	294	294
query70	1002	953	913	913
query71	333	346	311	311
query72	3083	2899	2692	2692
query73	513	547	326	326
query74	9674	9638	9579	9579
query75	2812	2747	2437	2437
query76	2291	1067	664	664
query77	339	353	314	314
query78	11355	11438	10964	10964
query79	1124	868	592	592
query80	1260	572	482	482
query81	573	286	258	258
query82	980	151	114	114
query83	322	259	235	235
query84	244	125	97	97
query85	874	457	412	412
query86	416	317	299	299
query87	3196	3133	3002	3002
query88	3538	2641	2621	2621
query89	398	343	326	326
query90	1956	179	162	162
query91	162	147	131	131
query92	75	72	69	69
query93	994	836	481	481
query94	679	328	290	290
query95	585	325	377	325
query96	645	518	222	222
query97	2474	2459	2456	2456
query98	221	211	210	210
query99	965	927	846	846
Total cold run time: 262617 ms
Total hot run time: 190819 ms

@doris-robot

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

query1	0.05	0.05	0.05
query2	0.09	0.05	0.05
query3	0.26	0.09	0.08
query4	1.61	0.11	0.11
query5	0.29	0.24	0.25
query6	1.17	0.69	0.67
query7	0.04	0.02	0.03
query8	0.05	0.03	0.04
query9	0.56	0.48	0.48
query10	0.54	0.57	0.54
query11	0.14	0.10	0.10
query12	0.14	0.10	0.10
query13	0.64	0.63	0.61
query14	1.07	1.04	1.04
query15	0.88	0.86	0.88
query16	0.39	0.38	0.38
query17	1.14	1.15	1.13
query18	0.24	0.21	0.22
query19	2.12	1.96	1.93
query20	0.02	0.02	0.02
query21	15.42	0.30	0.15
query22	5.09	0.06	0.05
query23	16.01	0.28	0.12
query24	1.49	0.28	0.56
query25	0.10	0.09	0.08
query26	0.16	0.14	0.13
query27	0.05	0.04	0.08
query28	4.42	1.15	0.96
query29	12.55	3.94	3.18
query30	0.27	0.14	0.12
query31	2.82	0.63	0.41
query32	3.24	0.60	0.50
query33	3.15	3.28	3.25
query34	16.53	5.38	4.79
query35	4.77	4.84	4.72
query36	0.64	0.50	0.49
query37	0.10	0.08	0.07
query38	0.08	0.04	0.04
query39	0.04	0.03	0.04
query40	0.20	0.16	0.15
query41	0.08	0.03	0.03
query42	0.04	0.04	0.04
query43	0.04	0.04	0.03
Total cold run time: 98.73 s
Total hot run time: 28.31 s

@feiniaofeiafei

Copy link
Copy Markdown
Contributor Author

run buildall

@doris-robot

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

------ Round 1 ----------------------------------
q1	17644	4437	4269	4269
q2	2031	349	233	233
q3	10181	1316	749	749
q4	10203	826	319	319
q5	7627	2223	1910	1910
q6	190	175	149	149
q7	923	726	606	606
q8	9272	1431	1274	1274
q9	4735	4671	4681	4671
q10	6803	1954	1576	1576
q11	544	308	291	291
q12	354	383	231	231
q13	17760	4046	3238	3238
q14	230	252	231	231
q15	857	806	818	806
q16	675	687	636	636
q17	685	845	507	507
q18	6510	5863	6312	5863
q19	1146	1076	644	644
q20	556	558	430	430
q21	2848	2074	1979	1979
q22	384	337	316	316
Total cold run time: 102158 ms
Total hot run time: 30928 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4591	4530	4681	4530
q2	256	329	269	269
q3	2408	2943	2311	2311
q4	1478	1861	1591	1591
q5	4735	4569	4492	4492
q6	231	185	141	141
q7	2030	1860	1832	1832
q8	2528	2433	2465	2433
q9	7777	7340	7475	7340
q10	2928	3116	2626	2626
q11	536	494	469	469
q12	702	753	572	572
q13	3900	4405	3468	3468
q14	268	287	276	276
q15	822	782	771	771
q16	649	670	631	631
q17	1087	1333	1373	1333
q18	7739	7418	7384	7384
q19	887	833	840	833
q20	1965	2013	1876	1876
q21	4664	4258	4128	4128
q22	575	533	514	514
Total cold run time: 52756 ms
Total hot run time: 49820 ms

@doris-robot

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

query1	0.05	0.05	0.05
query2	0.08	0.04	0.04
query3	0.26	0.08	0.07
query4	1.60	0.11	0.11
query5	0.29	0.24	0.25
query6	1.17	0.68	0.67
query7	0.04	0.02	0.03
query8	0.05	0.04	0.04
query9	0.56	0.49	0.49
query10	0.56	0.55	0.54
query11	0.14	0.09	0.10
query12	0.15	0.10	0.10
query13	0.63	0.62	0.61
query14	1.07	1.05	1.06
query15	0.87	0.87	0.86
query16	0.38	0.38	0.39
query17	1.11	1.14	1.14
query18	0.24	0.22	0.21
query19	2.13	2.00	2.06
query20	0.02	0.01	0.02
query21	15.41	0.26	0.15
query22	5.05	0.06	0.05
query23	16.06	0.28	0.10
query24	1.88	0.35	0.44
query25	0.11	0.06	0.08
query26	0.15	0.14	0.13
query27	0.07	0.08	0.06
query28	3.94	1.15	0.97
query29	12.59	3.92	3.18
query30	0.27	0.14	0.11
query31	2.81	0.62	0.40
query32	3.24	0.60	0.52
query33	3.20	3.37	3.22
query34	15.91	5.44	4.69
query35	4.74	4.79	4.81
query36	0.64	0.50	0.50
query37	0.10	0.07	0.07
query38	0.08	0.05	0.03
query39	0.04	0.03	0.03
query40	0.19	0.16	0.16
query41	0.09	0.04	0.03
query42	0.04	0.03	0.02
query43	0.05	0.04	0.03
Total cold run time: 98.06 s
Total hot run time: 28.37 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 78.88% (127/161) 🎉
Increment coverage report
Complete coverage report

@feiniaofeiafei

Copy link
Copy Markdown
Contributor Author

run buildall

@doris-robot

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

------ Round 1 ----------------------------------
q1	17640	4420	4271	4271
q2	2049	340	226	226
q3	10177	1284	725	725
q4	10202	773	315	315
q5	7490	2189	1904	1904
q6	197	176	146	146
q7	891	744	593	593
q8	9247	1394	1126	1126
q9	4623	4610	4614	4610
q10	6817	1961	1553	1553
q11	524	287	290	287
q12	338	375	225	225
q13	17786	4021	3226	3226
q14	226	241	222	222
q15	887	814	799	799
q16	678	685	624	624
q17	703	817	515	515
q18	6541	5862	5795	5795
q19	1224	979	588	588
q20	492	494	377	377
q21	2549	1787	1765	1765
q22	356	316	275	275
Total cold run time: 101637 ms
Total hot run time: 30167 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4370	4359	4358	4358
q2	245	353	253	253
q3	2084	2632	2218	2218
q4	1346	1740	1304	1304
q5	4268	4192	4304	4192
q6	225	186	138	138
q7	1862	1772	1713	1713
q8	2485	2687	2435	2435
q9	7815	7619	7690	7619
q10	2876	3150	2713	2713
q11	573	500	447	447
q12	767	803	628	628
q13	3916	4448	3972	3972
q14	347	296	273	273
q15	845	812	798	798
q16	661	707	670	670
q17	1127	1394	1350	1350
q18	8393	7720	7970	7720
q19	953	891	856	856
q20	2102	2112	2011	2011
q21	4824	4237	4187	4187
q22	554	529	503	503
Total cold run time: 52638 ms
Total hot run time: 50358 ms

@doris-robot

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

query1	0.06	0.05	0.04
query2	0.11	0.05	0.05
query3	0.26	0.09	0.08
query4	1.61	0.11	0.10
query5	0.27	0.25	0.25
query6	1.18	0.67	0.68
query7	0.03	0.03	0.03
query8	0.05	0.05	0.04
query9	0.55	0.48	0.49
query10	0.57	0.55	0.55
query11	0.13	0.10	0.09
query12	0.14	0.10	0.11
query13	0.63	0.61	0.63
query14	1.05	1.04	1.04
query15	0.88	0.87	0.87
query16	0.39	0.40	0.38
query17	1.15	1.15	1.18
query18	0.23	0.22	0.21
query19	2.13	1.98	1.91
query20	0.02	0.01	0.01
query21	15.40	0.28	0.15
query22	5.06	0.07	0.06
query23	15.92	0.28	0.11
query24	1.50	0.25	0.20
query25	0.08	0.08	0.06
query26	0.14	0.13	0.14
query27	0.07	0.08	0.05
query28	3.82	1.16	0.97
query29	12.57	3.96	3.17
query30	0.29	0.15	0.12
query31	2.82	0.66	0.40
query32	3.24	0.59	0.50
query33	3.26	3.28	3.38
query34	15.88	5.40	4.76
query35	4.78	4.81	4.82
query36	0.67	0.51	0.49
query37	0.12	0.07	0.07
query38	0.08	0.04	0.04
query39	0.05	0.03	0.03
query40	0.20	0.16	0.16
query41	0.09	0.05	0.03
query42	0.05	0.03	0.03
query43	0.04	0.04	0.04
Total cold run time: 97.57 s
Total hot run time: 28.32 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 82.61% (133/161) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 88.82% (143/161) 🎉
Increment coverage report
Complete coverage report

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added approved Indicates a PR has been approved by one committer. reviewed labels Feb 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR approved by anyone and no changes requested.

@morrySnow
morrySnow merged commit 32ec896 into apache:master Feb 10, 2026
30 checks passed
feiniaofeiafei added a commit to feiniaofeiafei/doris that referenced this pull request Mar 12, 2026
…ation in DecomposeRepeatWithPreAggregation (apache#60091)

Related PR: apache#59116 apache#60045

**Problem Summary:**
There are 2 problems:

1. When `DecomposeRepeatWithPreAggregation` optimization removes the
maximum grouping set, grouping functions (e.g., `grouping()`,
`grouping_id()`) that reference expressions only existing in the removed
grouping set would fail because of index lookup failure: When computing
grouping function values, `GroupingSetShapes.indexOf()` would return -1
for expressions not in `flattenGroupingSetExpression`, causing incorrect
behavior.

Example scenario:
```sql
SELECT a, b, c, grouping(c) 
FROM t1 
GROUP BY GROUPING SETS ((a, b, c), (a, b), (a), ());
```
After optimization removes the maximum grouping set `(a, b, c)`, the
expression `c` no longer exists in the remaining grouping sets. When
computing `grouping(c)`, the index lookup would fail.

2. The `repeatSlotIdList` calculation was incorrect because it relied on
the assumption that the order of `physicalRepeat.getOutputExpressions()`
matches the order of `outputTuple`. However, this assumption can be
broken during rule rewriting (e.g., in
`DecomposeRepeatWithPreAggregation.constructRepeat()` at line 502-503,
where `replacedRepeatOutputs` is constructed by `new
ArrayList<>(child.getOutput())` and then appends grouping functions,
potentially changing the order). This mismatch causes incorrect slot ID
mapping and wrong query results.

Example scenario:
When `DecomposeRepeatWithPreAggregation` rewrites a repeat plan, the
output expressions order may differ from the output tuple order, leading
to incorrect slot ID mapping in `repeatSlotIdList`.


**Solution:**

1. For problem 1: Modified `Repeat.toShapes()` method to ensure all
expressions referenced by grouping functions are included in
`flattenGroupingSetExpression`, even if they are not in any grouping
set. For expressions that only exist in the removed maximum grouping
set, they are correctly marked as `shouldBeErasedToNull = true` in all
remaining grouping sets, which is the correct SQL semantics.

Key changes:
- `Repeat.toShapes()`: Enhanced to collect all expressions referenced by
grouping functions using `ExpressionUtils.collectToList()` and merge
them into `flattenGroupingSetExpression`
- For expressions not in any grouping set, they are correctly marked as
`shouldBeErasedToNull = true` in all `GroupingSetShape` instances
- This ensures `GroupingSetShapes.indexOf()` always returns a valid
index for grouping function arguments, preventing index lookup failures

2. For problem 2: Modified `Repeat.computeRepeatSlotIdList()` method to
accept an additional `outputSlots` parameter. Instead of relying on the
order of `outputExpressions` matching `outputTuple`, the method now uses
`outputSlots` to correctly map grouping set expressions to their indices
in the output tuple. This ensures correct slot ID calculation even when
rule rewriting changes the order of output expressions.

Key changes:
- `computeRepeatSlotIdList(List<Integer> slotIdList, List<Slot>
outputSlots)`: Added `outputSlots` parameter
- `getGroupingSetsIndexesInOutput(List<Slot> outputSlots)`: Modified to
use `outputSlots` instead of `getOutputExpressions()`
- `indexesOfOutput(List<Slot> outputSlots)`: Modified to build index map
from `outputSlots` instead of `getOutputExpressions()`
- `PhysicalPlanTranslator.visitPhysicalRepeat()`: Updated to pass
`outputSlots` to `computeRepeatSlotIdList()`

3. Another task for this pull request is to set the shuffle key for the
rewritten bottom aggregation. Choosing a suitable shuffle key can
improve the aggregation rate of the top aggregation's local aggregation.
feiniaofeiafei added a commit to feiniaofeiafei/doris that referenced this pull request Mar 13, 2026
…ation in DecomposeRepeatWithPreAggregation (apache#60091)

Related PR: apache#59116 apache#60045

**Problem Summary:**
There are 2 problems:

1. When `DecomposeRepeatWithPreAggregation` optimization removes the
maximum grouping set, grouping functions (e.g., `grouping()`,
`grouping_id()`) that reference expressions only existing in the removed
grouping set would fail because of index lookup failure: When computing
grouping function values, `GroupingSetShapes.indexOf()` would return -1
for expressions not in `flattenGroupingSetExpression`, causing incorrect
behavior.

Example scenario:
```sql
SELECT a, b, c, grouping(c) 
FROM t1 
GROUP BY GROUPING SETS ((a, b, c), (a, b), (a), ());
```
After optimization removes the maximum grouping set `(a, b, c)`, the
expression `c` no longer exists in the remaining grouping sets. When
computing `grouping(c)`, the index lookup would fail.

2. The `repeatSlotIdList` calculation was incorrect because it relied on
the assumption that the order of `physicalRepeat.getOutputExpressions()`
matches the order of `outputTuple`. However, this assumption can be
broken during rule rewriting (e.g., in
`DecomposeRepeatWithPreAggregation.constructRepeat()` at line 502-503,
where `replacedRepeatOutputs` is constructed by `new
ArrayList<>(child.getOutput())` and then appends grouping functions,
potentially changing the order). This mismatch causes incorrect slot ID
mapping and wrong query results.

Example scenario:
When `DecomposeRepeatWithPreAggregation` rewrites a repeat plan, the
output expressions order may differ from the output tuple order, leading
to incorrect slot ID mapping in `repeatSlotIdList`.


**Solution:**

1. For problem 1: Modified `Repeat.toShapes()` method to ensure all
expressions referenced by grouping functions are included in
`flattenGroupingSetExpression`, even if they are not in any grouping
set. For expressions that only exist in the removed maximum grouping
set, they are correctly marked as `shouldBeErasedToNull = true` in all
remaining grouping sets, which is the correct SQL semantics.

Key changes:
- `Repeat.toShapes()`: Enhanced to collect all expressions referenced by
grouping functions using `ExpressionUtils.collectToList()` and merge
them into `flattenGroupingSetExpression`
- For expressions not in any grouping set, they are correctly marked as
`shouldBeErasedToNull = true` in all `GroupingSetShape` instances
- This ensures `GroupingSetShapes.indexOf()` always returns a valid
index for grouping function arguments, preventing index lookup failures

2. For problem 2: Modified `Repeat.computeRepeatSlotIdList()` method to
accept an additional `outputSlots` parameter. Instead of relying on the
order of `outputExpressions` matching `outputTuple`, the method now uses
`outputSlots` to correctly map grouping set expressions to their indices
in the output tuple. This ensures correct slot ID calculation even when
rule rewriting changes the order of output expressions.

Key changes:
- `computeRepeatSlotIdList(List<Integer> slotIdList, List<Slot>
outputSlots)`: Added `outputSlots` parameter
- `getGroupingSetsIndexesInOutput(List<Slot> outputSlots)`: Modified to
use `outputSlots` instead of `getOutputExpressions()`
- `indexesOfOutput(List<Slot> outputSlots)`: Modified to build index map
from `outputSlots` instead of `getOutputExpressions()`
- `PhysicalPlanTranslator.visitPhysicalRepeat()`: Updated to pass
`outputSlots` to `computeRepeatSlotIdList()`

3. Another task for this pull request is to set the shuffle key for the
rewritten bottom aggregation. Choosing a suitable shuffle key can
improve the aggregation rate of the top aggregation's local aggregation.
yiguolei pushed a commit that referenced this pull request Mar 13, 2026
…eAggregation (#59116) (#61301)

picked from #59116 #60045 #59876 #60091 #60811

---------

Co-authored-by: yujun <yujun@selectdb.com>
yiguolei pushed a commit that referenced this pull request Mar 16, 2026
…eAggregation (#59116) (#61301)

picked from #59116 #60045 #59876 #60091 #60811

---------

Co-authored-by: yujun <yujun@selectdb.com>
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.0-merged reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants