Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix](nereids) fix NormalizeRepeat, change the outputExpression rewrite logic #34196

Merged
merged 6 commits into from
May 8, 2024

Conversation

feiniaofeiafei
Copy link
Contributor

@feiniaofeiafei feiniaofeiafei commented Apr 26, 2024

In NormalizeRepeat, three parts of the outputExpression of LogicalRepeat need to be pushed down and outputted by bottom project: flattenGroupingSetExpr, argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction.
In the original code, use these three parts to rewrite the outputExpressions of LogicalRepeat to slots.This can cause problems in some cases, for example:

SELECT
	ROUND( SUM(pk + 1) - 3) col_alias1,
	pk + 1 AS col_alias3 
	FROM
	table_20_undef_partitions2_keys3_properties4_distributed_by53
GROUP BY
	GROUPING SETS ((pk), ()) ;

The three parts expression needed to be pushed down are: pk, pk+1. The original code use pk+1 to rewrite the pk + 1 AS col_alias3 to slot. But the pk+1 is not in the list of grouping outputs, and then report error.
This pr change the rewrite process, divide the expression needed to be pushed down into 2 parts: one is (flattenGroupingSetExpr) and the other one is (argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction).
and use the flattenGroupingSetExpr rewrite all LogicalRepeat outputExpressions, and use the argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction to rewrite only the agg function arguments and the grouping scalar function.
So, in the above sql, the pk + 1 AS col_alias3 will not be rewritten to slot, and can be computed.

@doris-robot
Copy link

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR

Since 2024-03-18, the Document has been moved to doris-website.
See Doris Document.

@feiniaofeiafei
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17600	4260	4224	4224
q2	2019	181	190	181
q3	10467	1166	1277	1166
q4	10193	889	807	807
q5	7579	2740	2774	2740
q6	223	130	135	130
q7	1025	638	631	631
q8	9236	2122	2110	2110
q9	10118	6792	6885	6792
q10	9303	3887	3934	3887
q11	439	239	236	236
q12	416	228	223	223
q13	17264	3124	3252	3124
q14	290	236	230	230
q15	519	475	456	456
q16	491	400	403	400
q17	973	730	679	679
q18	8339	7739	7705	7705
q19	3771	1542	1537	1537
q20	613	321	323	321
q21	5178	4103	3322	3322
q22	353	276	271	271
Total cold run time: 116409 ms
Total hot run time: 41172 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4522	4392	4475	4392
q2	377	270	269	269
q3	3264	2940	3022	2940
q4	1891	1585	1556	1556
q5	5524	5491	5502	5491
q6	219	123	128	123
q7	2304	1998	1964	1964
q8	3241	3380	3377	3377
q9	8901	8902	8896	8896
q10	3939	3711	3808	3711
q11	582	488	491	488
q12	805	616	634	616
q13	15841	3116	3162	3116
q14	296	280	271	271
q15	534	475	490	475
q16	481	449	453	449
q17	1784	1533	1481	1481
q18	7853	7590	7552	7552
q19	1632	1522	1544	1522
q20	1988	1789	1733	1733
q21	10126	4665	4803	4665
q22	557	495	500	495
Total cold run time: 76661 ms
Total hot run time: 55582 ms

@feiniaofeiafei
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17605	4310	4250	4250
q2	2024	192	194	192
q3	10460	1228	1211	1211
q4	10199	819	816	816
q5	7522	2761	2737	2737
q6	220	135	137	135
q7	1054	602	629	602
q8	9228	2144	2087	2087
q9	10093	7400	7391	7391
q10	9163	3965	3798	3798
q11	454	247	249	247
q12	467	224	223	223
q13	18268	3143	3174	3143
q14	273	240	221	221
q15	507	494	452	452
q16	510	402	399	399
q17	972	688	666	666
q18	8277	7689	7777	7689
q19	3185	1538	1541	1538
q20	641	319	313	313
q21	5230	3443	4186	3443
q22	333	276	275	275
Total cold run time: 116685 ms
Total hot run time: 41828 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4589	4373	4485	4373
q2	374	276	273	273
q3	3179	2960	3039	2960
q4	1930	1577	1613	1577
q5	5460	5527	5505	5505
q6	213	124	121	121
q7	2364	1964	2010	1964
q8	3266	3411	3415	3411
q9	9526	9547	9566	9547
q10	3933	3717	3870	3717
q11	591	496	499	496
q12	811	626	639	626
q13	17013	3152	3124	3124
q14	316	297	296	296
q15	504	502	478	478
q16	494	438	439	438
q17	1756	1488	1475	1475
q18	7574	7548	7542	7542
q19	1632	1564	1576	1564
q20	1956	1740	1793	1740
q21	9692	4686	4838	4686
q22	568	494	496	494
Total cold run time: 77741 ms
Total hot run time: 56407 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 186321 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 9cef3862e00057eb3fb94c984cc061fdeba21b13, data reload: false

query1	899	373	345	345
query2	6441	2346	2325	2325
query3	6632	221	210	210
query4	23587	21159	21353	21159
query5	4156	402	411	402
query6	274	180	169	169
query7	4593	291	282	282
query8	239	195	193	193
query9	8710	2374	2351	2351
query10	438	246	263	246
query11	14714	14155	14225	14155
query12	137	90	85	85
query13	1640	371	381	371
query14	10523	7938	7452	7452
query15	270	174	177	174
query16	8073	269	265	265
query17	1721	585	558	558
query18	2103	295	284	284
query19	331	153	154	153
query20	91	86	85	85
query21	202	127	131	127
query22	5104	4920	4879	4879
query23	33855	33068	33106	33068
query24	10168	3007	3003	3003
query25	589	396	388	388
query26	696	157	154	154
query27	2102	322	325	322
query28	5944	2050	2045	2045
query29	880	614	613	613
query30	249	155	155	155
query31	968	745	719	719
query32	92	52	56	52
query33	653	252	256	252
query34	882	477	491	477
query35	812	675	661	661
query36	1064	920	920	920
query37	106	68	74	68
query38	3148	3014	3096	3014
query39	1604	1538	1536	1536
query40	199	130	124	124
query41	46	42	41	41
query42	111	97	95	95
query43	559	545	548	545
query44	1061	727	738	727
query45	295	264	285	264
query46	1073	722	752	722
query47	1949	1849	1861	1849
query48	376	304	298	298
query49	903	399	387	387
query50	768	397	372	372
query51	6674	6618	6626	6618
query52	100	89	90	89
query53	347	274	272	272
query54	298	233	225	225
query55	73	71	70	70
query56	234	216	221	216
query57	1223	1125	1135	1125
query58	212	196	196	196
query59	3485	3286	3244	3244
query60	263	237	234	234
query61	89	86	87	86
query62	614	458	426	426
query63	299	270	269	269
query64	8147	7153	7135	7135
query65	3076	3029	3001	3001
query66	782	329	344	329
query67	15917	15207	15439	15207
query68	9714	569	565	565
query69	605	314	305	305
query70	1453	1097	1136	1097
query71	470	266	268	266
query72	8675	2606	2407	2407
query73	1619	332	335	332
query74	6549	6208	5977	5977
query75	4791	2688	2664	2664
query76	5532	942	1022	942
query77	719	258	281	258
query78	11192	10222	10220	10220
query79	11608	520	520	520
query80	2230	437	456	437
query81	491	226	220	220
query82	239	90	97	90
query83	216	164	166	164
query84	275	82	84	82
query85	873	263	253	253
query86	333	281	269	269
query87	3273	3035	3052	3035
query88	5359	2422	2414	2414
query89	508	379	365	365
query90	2011	181	179	179
query91	127	96	95	95
query92	61	46	49	46
query93	6453	539	514	514
query94	1340	180	178	178
query95	403	300	304	300
query96	604	263	267	263
query97	3130	2905	2916	2905
query98	232	216	212	212
query99	1153	864	876	864
Total cold run time: 306101 ms
Total hot run time: 186321 ms

@feiniaofeiafei
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17564	4342	4238	4238
q2	2021	194	188	188
q3	10473	1241	1199	1199
q4	10201	733	799	733
q5	7472	2731	2702	2702
q6	226	137	137	137
q7	1055	621	618	618
q8	9226	2152	2118	2118
q9	9377	6767	6778	6767
q10	9302	3914	3931	3914
q11	455	248	240	240
q12	520	213	226	213
q13	17301	3265	3192	3192
q14	273	240	225	225
q15	516	479	475	475
q16	506	405	394	394
q17	986	749	716	716
q18	8113	7766	7728	7728
q19	4311	1537	1561	1537
q20	657	337	324	324
q21	5377	3999	4258	3999
q22	366	295	290	290
Total cold run time: 116298 ms
Total hot run time: 41947 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4547	4410	4423	4410
q2	388	269	264	264
q3	3203	2889	2918	2889
q4	2071	1727	1598	1598
q5	5329	5521	5463	5463
q6	221	119	127	119
q7	2335	2016	1978	1978
q8	3308	3457	3444	3444
q9	8822	8773	8768	8768
q10	4062	3749	3866	3749
q11	584	499	501	499
q12	824	619	640	619
q13	16145	3123	3163	3123
q14	295	271	276	271
q15	545	469	490	469
q16	495	435	430	430
q17	1797	1514	1502	1502
q18	7723	7640	7330	7330
q19	4665	1561	1517	1517
q20	2024	1762	1767	1762
q21	13822	5140	5057	5057
q22	611	511	499	499
Total cold run time: 83816 ms
Total hot run time: 55760 ms

@doris-robot
Copy link

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

query1	906	354	353	353
query2	6461	2435	2344	2344
query3	6645	223	212	212
query4	22681	21432	21353	21353
query5	4094	424	422	422
query6	282	175	170	170
query7	4592	290	302	290
query8	241	185	195	185
query9	8555	2438	2425	2425
query10	432	256	254	254
query11	14680	14121	14217	14121
query12	146	93	86	86
query13	1646	386	396	386
query14	9303	8255	8142	8142
query15	210	179	179	179
query16	7205	285	279	279
query17	1280	588	572	572
query18	1931	291	292	291
query19	202	157	161	157
query20	95	90	87	87
query21	203	129	128	128
query22	5063	4867	4920	4867
query23	33595	33321	33446	33321
query24	5002	2965	2978	2965
query25	495	406	387	387
query26	689	166	153	153
query27	1831	330	344	330
query28	3565	2103	2080	2080
query29	844	638	623	623
query30	213	162	158	158
query31	906	747	742	742
query32	64	54	59	54
query33	398	264	257	257
query34	843	490	503	490
query35	782	685	686	685
query36	1063	907	885	885
query37	105	66	71	66
query38	3140	3026	3063	3026
query39	1584	1537	1541	1537
query40	205	128	129	128
query41	43	42	42	42
query42	112	102	98	98
query43	573	527	538	527
query44	1050	732	750	732
query45	280	254	258	254
query46	1082	705	737	705
query47	2003	1847	1871	1847
query48	379	305	308	305
query49	846	391	394	391
query50	768	388	398	388
query51	6810	6741	6688	6688
query52	106	89	88	88
query53	352	289	283	283
query54	269	240	242	240
query55	79	75	74	74
query56	237	222	224	222
query57	1216	1136	1169	1136
query58	218	204	199	199
query59	3369	3328	3043	3043
query60	266	227	236	227
query61	91	89	92	89
query62	560	452	438	438
query63	309	288	290	288
query64	7538	7262	7220	7220
query65	3111	3067	3087	3067
query66	707	335	337	335
query67	15880	15084	15054	15054
query68	7569	562	559	559
query69	559	320	350	320
query70	1213	1159	1152	1152
query71	531	283	277	277
query72	8105	2556	2352	2352
query73	748	332	333	332
query74	6503	6089	6085	6085
query75	4532	2658	2665	2658
query76	4714	987	1001	987
query77	727	266	271	266
query78	11195	10245	10344	10245
query79	12369	523	523	523
query80	2182	435	428	428
query81	513	220	227	220
query82	770	95	92	92
query83	202	165	167	165
query84	269	85	89	85
query85	1022	274	271	271
query86	404	270	291	270
query87	3299	3036	3076	3036
query88	5277	2447	2448	2447
query89	531	385	390	385
query90	2143	183	189	183
query91	131	98	99	98
query92	63	49	49	49
query93	7752	547	529	529
query94	1111	191	187	187
query95	1109	1097	1095	1095
query96	603	276	279	276
query97	3183	2923	2955	2923
query98	248	230	218	218
query99	1225	932	832	832
Total cold run time: 291233 ms
Total hot run time: 188715 ms

@feiniaofeiafei
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17692	4304	4256	4256
q2	2019	185	195	185
q3	10498	1276	1265	1265
q4	10713	851	773	773
q5	7526	2722	2663	2663
q6	220	136	141	136
q7	1030	620	611	611
q8	9274	2129	2095	2095
q9	9128	6709	6621	6621
q10	9447	3652	3698	3652
q11	468	252	246	246
q12	473	222	227	222
q13	17912	2935	2937	2935
q14	264	218	223	218
q15	518	488	461	461
q16	528	398	383	383
q17	949	690	707	690
q18	8149	7413	7330	7330
q19	1627	1542	1508	1508
q20	661	308	312	308
q21	5142	3936	4039	3936
q22	357	284	288	284
Total cold run time: 114595 ms
Total hot run time: 40778 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4270	4272	4216	4216
q2	372	257	261	257
q3	2971	2746	2715	2715
q4	1898	1553	1602	1553
q5	5287	5239	5284	5239
q6	209	126	130	126
q7	2253	1899	1885	1885
q8	3186	3317	3315	3315
q9	8433	8398	8450	8398
q10	3846	3705	3620	3620
q11	598	502	493	493
q12	760	604	597	597
q13	17536	2967	3003	2967
q14	298	276	262	262
q15	513	484	470	470
q16	471	419	425	419
q17	1757	1478	1463	1463
q18	7567	7643	7431	7431
q19	4382	1611	1493	1493
q20	2001	1740	1779	1740
q21	5183	4933	4982	4933
q22	585	495	487	487
Total cold run time: 74376 ms
Total hot run time: 54079 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 187086 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 4603182268f4b5c5f159c718c67078975f726d7c, data reload: false

query1	912	357	345	345
query2	6457	2523	2506	2506
query3	6645	210	209	209
query4	23814	21119	21242	21119
query5	4153	423	421	421
query6	282	182	188	182
query7	4593	296	288	288
query8	246	214	207	207
query9	8573	2462	2456	2456
query10	426	245	249	245
query11	14787	14261	14208	14208
query12	141	91	92	91
query13	1644	371	352	352
query14	8715	7711	7484	7484
query15	232	172	182	172
query16	8028	259	265	259
query17	1867	555	540	540
query18	2059	285	284	284
query19	234	148	152	148
query20	90	87	85	85
query21	201	127	130	127
query22	5014	4862	4780	4780
query23	33964	33251	33380	33251
query24	10692	2927	2967	2927
query25	614	357	355	355
query26	1402	151	147	147
query27	3031	319	338	319
query28	7542	2086	2067	2067
query29	906	601	606	601
query30	278	152	153	152
query31	969	733	725	725
query32	92	51	56	51
query33	768	252	239	239
query34	1093	474	493	474
query35	796	690	672	672
query36	1058	935	903	903
query37	146	67	71	67
query38	3204	2983	2958	2958
query39	1612	1544	1553	1544
query40	201	126	127	126
query41	42	39	38	38
query42	101	98	95	95
query43	595	562	571	562
query44	1167	725	732	725
query45	271	256	260	256
query46	1070	741	740	740
query47	1956	1873	1885	1873
query48	374	299	300	299
query49	1074	400	404	400
query50	776	386	397	386
query51	6955	6788	6783	6783
query52	107	89	95	89
query53	348	279	287	279
query54	303	234	260	234
query55	79	76	73	73
query56	246	222	222	222
query57	1229	1145	1156	1145
query58	225	195	199	195
query59	3432	3315	3305	3305
query60	253	237	237	237
query61	93	91	90	90
query62	656	462	456	456
query63	307	288	285	285
query64	8755	7210	7138	7138
query65	3161	3067	3049	3049
query66	960	357	350	350
query67	15530	14934	15045	14934
query68	5321	536	544	536
query69	501	321	316	316
query70	1167	1131	1177	1131
query71	428	273	271	271
query72	8050	2691	2497	2497
query73	701	338	343	338
query74	6493	6111	6152	6111
query75	3508	2613	2663	2613
query76	3359	1005	945	945
query77	452	277	275	275
query78	10981	10094	10170	10094
query79	8398	529	543	529
query80	1890	482	452	452
query81	537	221	217	217
query82	1316	99	98	98
query83	277	170	175	170
query84	268	88	89	88
query85	2120	318	315	315
query86	498	295	297	295
query87	3306	3067	3076	3067
query88	4934	2530	2429	2429
query89	498	381	373	373
query90	2032	181	185	181
query91	126	101	101	101
query92	63	45	47	45
query93	6247	526	515	515
query94	1247	184	193	184
query95	400	307	302	302
query96	610	276	267	267
query97	3155	2974	2936	2936
query98	239	225	206	206
query99	1248	877	865	865
Total cold run time: 297916 ms
Total hot run time: 187086 ms

@feiniaofeiafei
Copy link
Contributor Author

run external

@feiniaofeiafei
Copy link
Contributor Author

run cloud_p1

@feiniaofeiafei
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17659	4409	4350	4350
q2	2455	198	194	194
q3	11346	1183	1240	1183
q4	10550	856	796	796
q5	7645	2765	2675	2675
q6	222	141	135	135
q7	1046	612	588	588
q8	9223	2168	2085	2085
q9	9109	6625	6501	6501
q10	8964	3720	3698	3698
q11	460	245	240	240
q12	418	224	226	224
q13	17778	2975	2978	2975
q14	260	221	219	219
q15	510	482	483	482
q16	510	383	388	383
q17	962	636	750	636
q18	8016	7491	7308	7308
q19	1774	1501	1439	1439
q20	639	312	298	298
q21	5079	4040	4047	4040
q22	351	280	287	280
Total cold run time: 114976 ms
Total hot run time: 40729 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4359	4248	4265	4248
q2	367	263	269	263
q3	2948	2759	2713	2713
q4	1860	1588	1596	1588
q5	5277	5280	5299	5280
q6	211	124	126	124
q7	2239	1900	1892	1892
q8	3221	3368	3359	3359
q9	8460	8452	8493	8452
q10	3935	3710	3661	3661
q11	572	492	476	476
q12	760	595	584	584
q13	16295	2981	2971	2971
q14	286	289	258	258
q15	529	474	475	474
q16	460	419	424	419
q17	1758	1484	1458	1458
q18	7592	7580	7306	7306
q19	5381	1628	1559	1559
q20	2006	1785	1753	1753
q21	4888	4955	4812	4812
q22	576	497	503	497
Total cold run time: 73980 ms
Total hot run time: 54147 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 185318 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 9249becf15c07af488727d5fc872c44e47e1b9c1, data reload: false

query1	899	372	345	345
query2	6451	2467	2478	2467
query3	6650	204	202	202
query4	23761	21187	21204	21187
query5	4163	441	415	415
query6	281	201	178	178
query7	4593	290	286	286
query8	246	196	189	189
query9	8526	2356	2341	2341
query10	433	239	250	239
query11	14917	14264	14258	14258
query12	136	90	96	90
query13	1644	363	366	363
query14	10226	7521	6758	6758
query15	207	173	168	168
query16	7874	257	252	252
query17	1876	565	534	534
query18	1988	274	264	264
query19	204	152	153	152
query20	97	86	86	86
query21	198	132	128	128
query22	5103	4808	4870	4808
query23	33991	33370	33150	33150
query24	10889	2896	2877	2877
query25	639	386	386	386
query26	1206	157	149	149
query27	2981	319	326	319
query28	7206	2031	2059	2031
query29	889	633	619	619
query30	296	156	155	155
query31	971	742	733	733
query32	95	56	59	56
query33	763	262	262	262
query34	1038	476	494	476
query35	774	663	674	663
query36	1077	906	936	906
query37	133	65	73	65
query38	3171	2978	2999	2978
query39	1586	1541	1562	1541
query40	192	124	125	124
query41	41	39	37	37
query42	105	99	97	97
query43	587	533	542	533
query44	1207	731	748	731
query45	271	249	250	249
query46	1071	704	687	687
query47	1936	1853	1846	1846
query48	365	297	296	296
query49	1067	395	391	391
query50	778	383	395	383
query51	6830	6572	6618	6572
query52	119	87	93	87
query53	348	274	279	274
query54	298	237	241	237
query55	83	74	73	73
query56	238	217	218	217
query57	1236	1118	1160	1118
query58	234	205	223	205
query59	3450	3199	3282	3199
query60	269	235	230	230
query61	91	89	102	89
query62	656	439	466	439
query63	303	286	284	284
query64	8684	7219	7239	7219
query65	3286	3033	3052	3033
query66	1337	336	343	336
query67	15461	15054	14898	14898
query68	5192	527	524	524
query69	475	306	318	306
query70	1158	1101	1136	1101
query71	384	273	268	268
query72	7573	2589	2361	2361
query73	699	313	321	313
query74	6518	6050	6189	6050
query75	3348	2643	2612	2612
query76	2831	935	955	935
query77	419	315	264	264
query78	10821	10280	10232	10232
query79	7712	510	520	510
query80	1033	443	436	436
query81	531	219	227	219
query82	1012	98	96	96
query83	214	166	168	166
query84	276	84	85	84
query85	1435	273	264	264
query86	459	286	317	286
query87	3261	3084	3063	3063
query88	5317	2309	2333	2309
query89	503	379	376	376
query90	2025	183	184	183
query91	127	98	97	97
query92	61	48	48	48
query93	6198	516	508	508
query94	1175	186	195	186
query95	395	318	309	309
query96	599	274	257	257
query97	3131	2913	3004	2913
query98	234	234	219	219
query99	1228	863	871	863
Total cold run time: 295065 ms
Total hot run time: 185318 ms

@feiniaofeiafei feiniaofeiafei changed the title [Fix](nereids) fix NormalizeRepeat, only normalize grouping scalar function in agg outputExpressions with bottom projects [Fix](nereids) fix NormalizeRepeat, change the outputExpression rewrite logic May 6, 2024
morrySnow
morrySnow previously approved these changes May 6, 2024
Copy link
Contributor

github-actions bot commented May 6, 2024

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

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label May 6, 2024
Copy link
Contributor

github-actions bot commented May 6, 2024

PR approved by anyone and no changes requested.

// rewrite the arguments of grouping scalar function to slots
// rewrite grouping scalar function to virtual slots
// rewrite the arguments of agg function to slots
List<NamedExpression> normalizedAggOutput = repeat.getOutputExpressions().stream()
Copy link
Contributor

Choose a reason for hiding this comment

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

could we replace all stream api by for loop?

@feiniaofeiafei
Copy link
Contributor Author

run buildall

@github-actions github-actions bot removed the approved Indicates a PR has been approved by one committer. label May 7, 2024
@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	18142	4396	4442	4396
q2	2739	203	197	197
q3	11514	1181	1248	1181
q4	10615	825	822	822
q5	7505	2659	2658	2658
q6	217	137	137	137
q7	1029	601	562	562
q8	9222	2107	2067	2067
q9	9073	6601	6603	6601
q10	9035	3702	3719	3702
q11	483	251	245	245
q12	447	228	226	226
q13	17849	2962	2944	2944
q14	255	223	224	223
q15	514	474	464	464
q16	492	387	375	375
q17	981	733	675	675
q18	8048	7464	7430	7430
q19	4051	1529	1521	1521
q20	654	309	309	309
q21	5121	3864	4040	3864
q22	354	279	290	279
Total cold run time: 118340 ms
Total hot run time: 40878 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4372	4237	4217	4217
q2	381	271	263	263
q3	2953	2727	2695	2695
q4	1886	1561	1600	1561
q5	5302	5299	5323	5299
q6	217	130	131	130
q7	2256	1878	1875	1875
q8	3187	3397	3375	3375
q9	8453	8435	8461	8435
q10	3903	3704	3701	3701
q11	591	527	481	481
q12	746	598	579	579
q13	17452	2946	2976	2946
q14	282	259	270	259
q15	518	483	473	473
q16	460	422	406	406
q17	1816	1474	1462	1462
q18	7736	7616	7563	7563
q19	1674	1584	1573	1573
q20	1972	1793	1756	1756
q21	8712	4913	4879	4879
q22	626	496	504	496
Total cold run time: 75495 ms
Total hot run time: 54424 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 185654 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 4f8194601ceec6a7fe149a943374cbfcb4449072, data reload: false

query1	896	360	346	346
query2	6451	2336	2294	2294
query3	6655	207	213	207
query4	22694	21464	21121	21121
query5	4196	428	429	428
query6	268	183	173	173
query7	4587	295	309	295
query8	246	183	181	181
query9	8537	2423	2422	2422
query10	443	248	253	248
query11	14826	14078	14126	14078
query12	135	100	84	84
query13	1633	368	381	368
query14	10563	7529	7042	7042
query15	215	173	174	173
query16	7817	274	262	262
query17	1851	557	535	535
query18	1950	273	272	272
query19	214	150	151	150
query20	96	83	89	83
query21	198	128	127	127
query22	5151	4874	4826	4826
query23	33832	33030	32975	32975
query24	11617	3077	2908	2908
query25	642	370	365	365
query26	1630	154	152	152
query27	3061	325	312	312
query28	7538	2073	2063	2063
query29	1060	630	627	627
query30	299	152	156	152
query31	970	765	726	726
query32	93	55	56	55
query33	753	245	247	245
query34	1083	468	485	468
query35	879	676	673	673
query36	1110	923	880	880
query37	130	68	66	66
query38	3137	3061	2974	2974
query39	1657	1547	1522	1522
query40	282	128	127	127
query41	42	40	38	38
query42	100	97	95	95
query43	578	542	550	542
query44	1281	734	742	734
query45	276	255	249	249
query46	1171	777	750	750
query47	1977	1845	1848	1845
query48	388	298	301	298
query49	1147	395	391	391
query50	845	388	389	388
query51	6786	6615	6538	6538
query52	100	93	86	86
query53	385	283	284	283
query54	304	236	238	236
query55	82	74	76	74
query56	243	220	222	220
query57	1254	1163	1144	1144
query58	229	201	224	201
query59	3461	3146	3326	3146
query60	266	241	230	230
query61	88	100	85	85
query62	675	447	447	447
query63	313	285	284	284
query64	9968	7534	7590	7534
query65	3148	3036	3050	3036
query66	1410	354	365	354
query67	15248	14801	14872	14801
query68	5238	549	561	549
query69	472	302	302	302
query70	1178	1078	1081	1078
query71	405	270	262	262
query72	7148	2583	2341	2341
query73	767	336	339	336
query74	6459	5976	6055	5976
query75	3523	2650	2678	2650
query76	3369	1114	1069	1069
query77	447	268	264	264
query78	11035	10168	10281	10168
query79	7613	515	534	515
query80	1463	458	438	438
query81	526	221	223	221
query82	1602	96	93	93
query83	245	167	165	165
query84	273	85	89	85
query85	1598	270	265	265
query86	481	304	299	299
query87	3318	3059	3104	3059
query88	5190	2438	2447	2438
query89	517	402	379	379
query90	1993	192	193	192
query91	127	99	99	99
query92	63	50	50	50
query93	6155	530	521	521
query94	1216	188	195	188
query95	399	312	312	312
query96	671	270	268	268
query97	3227	2978	2997	2978
query98	243	231	216	216
query99	1268	871	844	844
Total cold run time: 299389 ms
Total hot run time: 185654 ms

@feiniaofeiafei
Copy link
Contributor Author

run p0

@feiniaofeiafei
Copy link
Contributor Author

run cloud_p1

@feiniaofeiafei
Copy link
Contributor Author

run buildall

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label May 8, 2024
Copy link
Contributor

github-actions bot commented May 8, 2024

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

@924060929 924060929 merged commit 65e4f08 into apache:master May 8, 2024
24 of 28 checks passed
yiguolei pushed a commit that referenced this pull request May 10, 2024
…te logic (#34196)

In NormalizeRepeat, three parts of the outputExpression of LogicalRepeat need to be pushed down and outputted by bottom project: flattenGroupingSetExpr, argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction.
In the original code, use these three parts to rewrite the outputExpressions of LogicalRepeat to slots.This can cause problems in some cases, for example:
```sql
SELECT
	ROUND( SUM(pk + 1) - 3) col_alias1,
	pk + 1 AS col_alias3 
	FROM
	table_20_undef_partitions2_keys3_properties4_distributed_by53
GROUP BY
	GROUPING SETS ((pk), ()) ;
```
The three parts expression needed to be pushed down are: pk, pk+1. The original code use pk+1 to rewrite the pk + 1 AS col_alias3  to slot. But the pk+1 is not in the list of grouping outputs, and then report error.
This pr change the rewrite process,  divide the expression needed to be pushed down  into 2 parts: one is (flattenGroupingSetExpr) and the other one is (argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction).
 and use the flattenGroupingSetExpr rewrite all LogicalRepeat outputExpressions, and use the argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction to rewrite only the agg function arguments and the grouping scalar function.
So, in the above sql, the pk + 1 AS col_alias3  will not be rewritten to slot, and can be computed.
ByteYue pushed a commit to ByteYue/doris that referenced this pull request May 15, 2024
…te logic (apache#34196)

In NormalizeRepeat, three parts of the outputExpression of LogicalRepeat need to be pushed down and outputted by bottom project: flattenGroupingSetExpr, argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction.
In the original code, use these three parts to rewrite the outputExpressions of LogicalRepeat to slots.This can cause problems in some cases, for example:
```sql
SELECT
	ROUND( SUM(pk + 1) - 3) col_alias1,
	pk + 1 AS col_alias3 
	FROM
	table_20_undef_partitions2_keys3_properties4_distributed_by53
GROUP BY
	GROUPING SETS ((pk), ()) ;
```
The three parts expression needed to be pushed down are: pk, pk+1. The original code use pk+1 to rewrite the pk + 1 AS col_alias3  to slot. But the pk+1 is not in the list of grouping outputs, and then report error.
This pr change the rewrite process,  divide the expression needed to be pushed down  into 2 parts: one is (flattenGroupingSetExpr) and the other one is (argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction).
 and use the flattenGroupingSetExpr rewrite all LogicalRepeat outputExpressions, and use the argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction to rewrite only the agg function arguments and the grouping scalar function.
So, in the above sql, the pk + 1 AS col_alias3  will not be rewritten to slot, and can be computed.
morrySnow pushed a commit that referenced this pull request Jul 26, 2024
Induced by #34196.

In NormalizeRepeat, when NormalizeToSlot is called, aggregate function
parameters, grouping scalar function parameters, and all expressions in
grouping sets (including columns and column aliases) are pushed down to
the lower-level project output.
In the previous PR #34196, the context was split into two, but the two
contexts were not consistent. It is possible that the triplets in one
context save (id, c1, id as c1), and the triplets in the other context
save (id, id, id).
This causes id as c1 to be pushed down, but there is a reference to id
in the upper-level LogicalRepeat, which causes the slot to be not found.
This pr has been modified.
If the same slot in the projection column has different aliases,

for example,

select id as c1, id, id as c3, grouping(id) from table1 group by grouping sets((id, value2),(id));

then id as c1 (using the first alias) will be pushed down to the
project.
In both the LogicalRepeat operator and the LogicalAggregate operator, c1
is referenced as the input slot, and id and c3 will not be used as input
slots.

before NormalizeRepeat:
LogicalResultSink[32] ( outputExprs=[c1#3, id#0, c3#4, __grouping_3#5] )
+--LogicalRepeat ( groupingSets=[[id#0, value2#2], [id#0]], outputExpressions=[id#0 AS `c1`#3, id#0, id#0 AS `c3`#4, Grouping(id#0) AS `Grouping(id)`#5] )
   +--LogicalOlapScan (qualified=table1)

After NormalizeRepeat:
LogicalResultSink[33] (outputExprs=[c1#3, id#0, c3#4, __grouping_3#5])
+--LogicalAggregate[30] (groupByExpr=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)], outputExpr=[c1#3, c1#3 AS `id`#0, c1#3 AS `c3`#4, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3) AS `GROUPING_PREFIX_c1`#5], hasRepeat=true )
   +--LogicalRepeat (groupingSets=[[c1#3, value2#2], [c1#3]], outputExpressions=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)] )
      +--LogicalProject[28] (projects=[id#0 AS `c1`#3, value2#2])
         +--LogicalOlapScan (qualified=table1)
feiniaofeiafei added a commit to feiniaofeiafei/doris that referenced this pull request Jul 29, 2024
Induced by apache#34196.

In NormalizeRepeat, when NormalizeToSlot is called, aggregate function
parameters, grouping scalar function parameters, and all expressions in
grouping sets (including columns and column aliases) are pushed down to
the lower-level project output.
In the previous PR apache#34196, the context was split into two, but the two
contexts were not consistent. It is possible that the triplets in one
context save (id, c1, id as c1), and the triplets in the other context
save (id, id, id).
This causes id as c1 to be pushed down, but there is a reference to id
in the upper-level LogicalRepeat, which causes the slot to be not found.
This pr has been modified.
If the same slot in the projection column has different aliases,

for example,

select id as c1, id, id as c3, grouping(id) from table1 group by grouping sets((id, value2),(id));

then id as c1 (using the first alias) will be pushed down to the
project.
In both the LogicalRepeat operator and the LogicalAggregate operator, c1
is referenced as the input slot, and id and c3 will not be used as input
slots.

before NormalizeRepeat:
LogicalResultSink[32] ( outputExprs=[c1#3, id#0, c3#4, __grouping_3#5] )
+--LogicalRepeat ( groupingSets=[[id#0, value2#2], [id#0]], outputExpressions=[id#0 AS `c1`apache#3, id#0, id#0 AS `c3`apache#4, Grouping(id#0) AS `Grouping(id)`apache#5] )
   +--LogicalOlapScan (qualified=table1)

After NormalizeRepeat:
LogicalResultSink[33] (outputExprs=[c1#3, id#0, c3#4, __grouping_3#5])
+--LogicalAggregate[30] (groupByExpr=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)], outputExpr=[c1#3, c1#3 AS `id`#0, c1#3 AS `c3`apache#4, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3) AS `GROUPING_PREFIX_c1`apache#5], hasRepeat=true )
   +--LogicalRepeat (groupingSets=[[c1#3, value2#2], [c1#3]], outputExpressions=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)] )
      +--LogicalProject[28] (projects=[id#0 AS `c1`apache#3, value2#2])
         +--LogicalOlapScan (qualified=table1)
feiniaofeiafei added a commit to feiniaofeiafei/doris that referenced this pull request Jul 30, 2024
Induced by apache#34196.

In NormalizeRepeat, when NormalizeToSlot is called, aggregate function
parameters, grouping scalar function parameters, and all expressions in
grouping sets (including columns and column aliases) are pushed down to
the lower-level project output.
In the previous PR apache#34196, the context was split into two, but the two
contexts were not consistent. It is possible that the triplets in one
context save (id, c1, id as c1), and the triplets in the other context
save (id, id, id).
This causes id as c1 to be pushed down, but there is a reference to id
in the upper-level LogicalRepeat, which causes the slot to be not found.
This pr has been modified.
If the same slot in the projection column has different aliases,

for example,

select id as c1, id, id as c3, grouping(id) from table1 group by grouping sets((id, value2),(id));

then id as c1 (using the first alias) will be pushed down to the
project.
In both the LogicalRepeat operator and the LogicalAggregate operator, c1
is referenced as the input slot, and id and c3 will not be used as input
slots.

before NormalizeRepeat:
LogicalResultSink[32] ( outputExprs=[c1#3, id#0, c3#4, __grouping_3#5] )
+--LogicalRepeat ( groupingSets=[[id#0, value2#2], [id#0]], outputExpressions=[id#0 AS `c1`apache#3, id#0, id#0 AS `c3`apache#4, Grouping(id#0) AS `Grouping(id)`apache#5] )
   +--LogicalOlapScan (qualified=table1)

After NormalizeRepeat:
LogicalResultSink[33] (outputExprs=[c1#3, id#0, c3#4, __grouping_3#5])
+--LogicalAggregate[30] (groupByExpr=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)], outputExpr=[c1#3, c1#3 AS `id`#0, c1#3 AS `c3`apache#4, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3) AS `GROUPING_PREFIX_c1`apache#5], hasRepeat=true )
   +--LogicalRepeat (groupingSets=[[c1#3, value2#2], [c1#3]], outputExpressions=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)] )
      +--LogicalProject[28] (projects=[id#0 AS `c1`apache#3, value2#2])
         +--LogicalOlapScan (qualified=table1)
dataroaring pushed a commit that referenced this pull request Aug 2, 2024
Induced by #34196.

In NormalizeRepeat, when NormalizeToSlot is called, aggregate function
parameters, grouping scalar function parameters, and all expressions in
grouping sets (including columns and column aliases) are pushed down to
the lower-level project output.
In the previous PR #34196, the context was split into two, but the two
contexts were not consistent. It is possible that the triplets in one
context save (id, c1, id as c1), and the triplets in the other context
save (id, id, id).
This causes id as c1 to be pushed down, but there is a reference to id
in the upper-level LogicalRepeat, which causes the slot to be not found.
This pr has been modified.
If the same slot in the projection column has different aliases,

for example,

select id as c1, id, id as c3, grouping(id) from table1 group by grouping sets((id, value2),(id));

then id as c1 (using the first alias) will be pushed down to the
project.
In both the LogicalRepeat operator and the LogicalAggregate operator, c1
is referenced as the input slot, and id and c3 will not be used as input
slots.

before NormalizeRepeat:
LogicalResultSink[32] ( outputExprs=[c1#3, id#0, c3#4, __grouping_3#5] )
+--LogicalRepeat ( groupingSets=[[id#0, value2#2], [id#0]], outputExpressions=[id#0 AS `c1`#3, id#0, id#0 AS `c3`#4, Grouping(id#0) AS `Grouping(id)`#5] )
   +--LogicalOlapScan (qualified=table1)

After NormalizeRepeat:
LogicalResultSink[33] (outputExprs=[c1#3, id#0, c3#4, __grouping_3#5])
+--LogicalAggregate[30] (groupByExpr=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)], outputExpr=[c1#3, c1#3 AS `id`#0, c1#3 AS `c3`#4, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3) AS `GROUPING_PREFIX_c1`#5], hasRepeat=true )
   +--LogicalRepeat (groupingSets=[[c1#3, value2#2], [c1#3]], outputExpressions=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)] )
      +--LogicalProject[28] (projects=[id#0 AS `c1`#3, value2#2])
         +--LogicalOlapScan (qualified=table1)
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/2.1.3-merged dev/3.0.0-merged reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants