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

[opt](Nereids) Replace Slot in Each Data Trait Separately #36886

Merged
merged 5 commits into from
Jul 3, 2024

Conversation

keanji-x
Copy link
Contributor

@keanji-x keanji-x commented Jun 27, 2024

Proposed changes

To avoid replacing slots in each data trait repeatedly, we split the replace function into four functions and replaced them separately.

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

@keanji-x
Copy link
Contributor Author

run buildall

@keanji-x keanji-x changed the title [opt](Nereids) Replace Slot in Each Data Trait Seperately [opt](Nereids) Replace Slot in Each Data Trait Separately Jun 27, 2024
@keanji-x
Copy link
Contributor Author

run buildall

Copy link
Contributor

PR approved by anyone and no changes requested.

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17613	4343	4255	4255
q2	2010	190	195	190
q3	10470	1239	1091	1091
q4	10177	853	731	731
q5	7489	2678	2636	2636
q6	218	135	136	135
q7	934	588	615	588
q8	9220	2070	2049	2049
q9	8803	6544	6465	6465
q10	8928	3739	3673	3673
q11	448	238	240	238
q12	475	233	236	233
q13	17781	2999	2983	2983
q14	257	236	223	223
q15	526	469	492	469
q16	508	379	374	374
q17	955	648	720	648
q18	8015	7444	7385	7385
q19	6083	1405	1432	1405
q20	650	315	333	315
q21	5020	3239	3281	3239
q22	377	334	336	334
Total cold run time: 116957 ms
Total hot run time: 39659 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4385	4230	4245	4230
q2	361	274	263	263
q3	2927	2848	2865	2848
q4	2034	1757	1717	1717
q5	5611	5508	5484	5484
q6	219	127	130	127
q7	2209	1888	1870	1870
q8	3235	3396	3420	3396
q9	8740	8739	8861	8739
q10	4158	3774	3766	3766
q11	608	503	497	497
q12	825	647	644	644
q13	17013	3152	3179	3152
q14	306	277	264	264
q15	535	510	482	482
q16	479	431	438	431
q17	1810	1531	1504	1504
q18	8064	7867	7734	7734
q19	1848	1656	1654	1654
q20	3070	1892	1835	1835
q21	5117	4917	4817	4817
q22	741	536	536	536
Total cold run time: 74295 ms
Total hot run time: 55990 ms

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17600	4346	4267	4267
q2	2019	193	201	193
q3	10468	1146	1041	1041
q4	10200	742	708	708
q5	7509	2648	2600	2600
q6	215	131	134	131
q7	948	604	598	598
q8	9219	2061	2038	2038
q9	8839	6457	6476	6457
q10	8966	3741	3686	3686
q11	454	223	228	223
q12	527	227	225	225
q13	18943	2974	2988	2974
q14	254	211	222	211
q15	523	472	478	472
q16	521	377	380	377
q17	960	619	691	619
q18	7990	7362	7337	7337
q19	5519	1529	1392	1392
q20	664	312	323	312
q21	5086	3250	3223	3223
q22	394	336	328	328
Total cold run time: 117818 ms
Total hot run time: 39412 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4385	4173	4220	4173
q2	354	269	271	269
q3	2995	2847	2865	2847
q4	1967	1786	1716	1716
q5	5680	5516	5522	5516
q6	223	128	124	124
q7	2218	1911	1856	1856
q8	3218	3380	3398	3380
q9	8675	8636	8717	8636
q10	4095	3882	3666	3666
q11	591	514	524	514
q12	825	620	644	620
q13	17023	3125	3143	3125
q14	314	253	288	253
q15	527	482	480	480
q16	480	436	435	435
q17	1813	1498	1498	1498
q18	8085	7892	7883	7883
q19	1814	1681	1638	1638
q20	2092	1858	1840	1840
q21	5065	5144	4715	4715
q22	610	577	545	545
Total cold run time: 73049 ms
Total hot run time: 55729 ms

@keanji-x
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17628	4420	4247	4247
q2	2019	195	196	195
q3	10452	1140	1105	1105
q4	10191	764	746	746
q5	7476	2595	2613	2595
q6	217	139	135	135
q7	939	588	600	588
q8	9221	2061	2048	2048
q9	8963	6502	6509	6502
q10	8968	3708	3682	3682
q11	460	240	233	233
q12	540	231	221	221
q13	17769	2956	2994	2956
q14	255	215	208	208
q15	540	474	480	474
q16	478	377	369	369
q17	959	738	695	695
q18	7980	7412	7333	7333
q19	4682	1540	1508	1508
q20	648	329	326	326
q21	5045	3845	3176	3176
q22	392	336	331	331
Total cold run time: 115822 ms
Total hot run time: 39673 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4340	4210	4254	4210
q2	378	276	262	262
q3	2998	2714	2884	2714
q4	1959	1703	1723	1703
q5	5541	5587	5501	5501
q6	224	132	132	132
q7	2190	1849	1925	1849
q8	3257	3404	3398	3398
q9	8705	8695	8726	8695
q10	4072	3880	3851	3851
q11	583	492	489	489
q12	786	649	641	641
q13	16307	3197	3120	3120
q14	306	268	286	268
q15	536	482	471	471
q16	485	437	445	437
q17	1814	1527	1514	1514
q18	8106	7872	7773	7773
q19	1817	1495	1668	1495
q20	3057	1884	1838	1838
q21	5216	5036	4982	4982
q22	635	550	554	550
Total cold run time: 73312 ms
Total hot run time: 55893 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 173999 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 98c256aed3ef2739f07f581335ede4156384d07c, data reload: false

query1	927	387	379	379
query2	6437	2407	2315	2315
query3	6636	207	213	207
query4	18698	17572	17388	17388
query5	3709	470	458	458
query6	266	171	161	161
query7	4592	299	290	290
query8	305	298	278	278
query9	8692	2427	2391	2391
query10	562	302	269	269
query11	10597	10017	10067	10017
query12	118	90	84	84
query13	1641	364	369	364
query14	9502	6948	6943	6943
query15	232	178	192	178
query16	7638	279	269	269
query17	1391	557	537	537
query18	1953	280	280	280
query19	192	162	155	155
query20	88	85	82	82
query21	213	133	125	125
query22	4326	4222	3991	3991
query23	33952	33674	33648	33648
query24	11318	2885	2986	2885
query25	644	406	394	394
query26	1219	162	154	154
query27	3020	328	318	318
query28	7458	2173	2160	2160
query29	922	650	653	650
query30	242	157	158	157
query31	998	766	771	766
query32	95	57	57	57
query33	774	303	301	301
query34	1046	477	484	477
query35	781	659	665	659
query36	1140	991	991	991
query37	163	78	78	78
query38	2951	2854	2877	2854
query39	907	842	824	824
query40	211	128	127	127
query41	53	52	54	52
query42	106	102	103	102
query43	608	541	528	528
query44	1245	741	724	724
query45	193	161	165	161
query46	1062	741	713	713
query47	1850	1742	1784	1742
query48	364	292	292	292
query49	854	401	404	401
query50	757	383	382	382
query51	6875	6831	6791	6791
query52	102	92	90	90
query53	357	284	293	284
query54	924	438	440	438
query55	74	72	73	72
query56	270	277	276	276
query57	1134	1028	1041	1028
query58	240	232	252	232
query59	3132	3201	3046	3046
query60	292	278	279	278
query61	93	87	91	87
query62	609	437	446	437
query63	310	288	295	288
query64	8856	2255	1806	1806
query65	3162	3079	3143	3079
query66	844	323	324	323
query67	15681	15099	15229	15099
query68	7785	562	570	562
query69	710	427	390	390
query70	1248	1130	1076	1076
query71	512	274	270	270
query72	8755	5354	5571	5354
query73	799	332	324	324
query74	5859	5457	5513	5457
query75	4816	2596	2689	2596
query76	4679	917	877	877
query77	782	302	298	298
query78	10447	9831	9699	9699
query79	7286	524	525	524
query80	979	461	473	461
query81	553	218	227	218
query82	289	101	105	101
query83	341	172	173	172
query84	275	83	85	83
query85	965	264	319	264
query86	369	310	314	310
query87	3307	3087	3073	3073
query88	4586	2372	2359	2359
query89	475	382	386	382
query90	2042	194	200	194
query91	136	99	98	98
query92	61	55	49	49
query93	5695	525	527	525
query94	1318	189	190	189
query95	396	311	317	311
query96	606	270	266	266
query97	3210	3067	3074	3067
query98	217	196	188	188
query99	1112	853	850	850
Total cold run time: 287213 ms
Total hot run time: 173999 ms

@doris-robot
Copy link

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

query1	0.04	0.03	0.03
query2	0.08	0.04	0.05
query3	0.22	0.06	0.05
query4	1.68	0.06	0.08
query5	0.52	0.48	0.48
query6	1.14	0.73	0.72
query7	0.02	0.01	0.02
query8	0.06	0.05	0.04
query9	0.55	0.50	0.49
query10	0.54	0.54	0.55
query11	0.15	0.11	0.11
query12	0.15	0.12	0.12
query13	0.59	0.58	0.60
query14	0.78	0.76	0.81
query15	0.82	0.82	0.81
query16	0.34	0.36	0.37
query17	1.04	0.97	1.01
query18	0.20	0.26	0.23
query19	1.78	1.69	1.75
query20	0.01	0.01	0.01
query21	15.43	0.79	0.66
query22	4.62	7.49	1.52
query23	18.24	1.40	1.25
query24	2.15	0.23	0.22
query25	0.15	0.09	0.09
query26	0.27	0.17	0.18
query27	0.08	0.08	0.08
query28	13.25	1.02	1.00
query29	12.65	3.34	3.34
query30	0.26	0.07	0.05
query31	2.90	0.39	0.39
query32	3.28	0.48	0.46
query33	2.90	2.92	2.95
query34	16.95	4.44	4.37
query35	4.51	4.53	4.51
query36	0.66	0.47	0.47
query37	0.19	0.15	0.15
query38	0.16	0.14	0.15
query39	0.04	0.03	0.04
query40	0.17	0.15	0.14
query41	0.08	0.04	0.05
query42	0.06	0.04	0.05
query43	0.04	0.04	0.04
Total cold run time: 109.75 s
Total hot run time: 30.18 s

Comment on lines 74 to 76
this.slots = this.slots.stream()
.map(s -> replaceMap.getOrDefault(s, s))
.collect(Collectors.toSet());
Copy link
Contributor

Choose a reason for hiding this comment

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

use for loop for better perf. in for loop u could use expected size collection to avoid resize it

Comment on lines 180 to 182
Set<Slot> key = e.getKey().stream()
.map(s -> replaceSlotMap.getOrDefault(s, s))
.collect(Collectors.toSet());
Copy link
Contributor

Choose a reason for hiding this comment

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

for loop

for (int i = 0; i < newOutputs.size(); i++) {
replaceMap.put(originalOutputs.get(i), newOutputs.get(i));
for (int i = 0; i < children.size(); i++) {
List<? extends Slot> originOutputs = this.regularChildrenOutputs.isEmpty()
Copy link
Contributor

Choose a reason for hiding this comment

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

this.regularChildrenOutputs.size() <= i

@@ -111,20 +111,29 @@ public LogicalIntersect withNewOutputs(List<NamedExpression> newOutputs) {

void replaceSlotInFuncDeps(DataTrait.Builder builder,
Copy link
Contributor

Choose a reason for hiding this comment

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

could be removed?

@@ -188,6 +188,6 @@ public void computeUniform(Builder builder) {
for (int i = 0; i < output.size(); i++) {
replaceMap.put(originalOutputs.get(i), output.get(i));
}
builder.replace(replaceMap);
builder.replaceUniformBy(replaceMap);
Copy link
Contributor

Choose a reason for hiding this comment

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

why not do same refactor as LogicalIntersect? there are same code in four functions too

@keanji-x
Copy link
Contributor Author

run buildall

@keanji-x keanji-x force-pushed the fix_replace_data_trait branch 2 times, most recently from d2a3c2b to a078836 Compare June 28, 2024 03:05
@keanji-x
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17600	4353	4247	4247
q2	2022	199	205	199
q3	10449	1213	1084	1084
q4	10190	778	833	778
q5	7497	2664	2641	2641
q6	218	134	135	134
q7	1048	619	602	602
q8	9233	2077	2032	2032
q9	8889	6480	6451	6451
q10	8996	3790	3691	3691
q11	440	238	232	232
q12	440	226	225	225
q13	17759	2982	3044	2982
q14	255	220	219	219
q15	514	479	461	461
q16	505	365	368	365
q17	952	649	604	604
q18	8077	7393	7454	7393
q19	7915	1502	1418	1418
q20	631	349	334	334
q21	4943	3130	4000	3130
q22	398	348	342	342
Total cold run time: 118971 ms
Total hot run time: 39564 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4460	4315	4197	4197
q2	357	261	265	261
q3	2978	2851	2914	2851
q4	1960	1701	1769	1701
q5	5511	5521	5458	5458
q6	225	125	126	125
q7	2213	1861	1830	1830
q8	3288	3472	3397	3397
q9	8713	8724	8785	8724
q10	4124	3754	3749	3749
q11	589	507	510	507
q12	813	622	648	622
q13	16254	3223	3217	3217
q14	317	289	280	280
q15	536	498	472	472
q16	486	430	438	430
q17	1840	1526	1511	1511
q18	8068	7829	7802	7802
q19	1772	1574	1666	1574
q20	3058	1869	1864	1864
q21	5085	5048	4711	4711
q22	625	562	552	552
Total cold run time: 73272 ms
Total hot run time: 55835 ms

@doris-robot
Copy link

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

query1	926	384	376	376
query2	6456	2441	2290	2290
query3	6645	208	209	208
query4	21270	17634	17420	17420
query5	3680	479	490	479
query6	258	172	173	172
query7	4589	295	296	295
query8	326	287	298	287
query9	8690	2460	2438	2438
query10	557	286	276	276
query11	10520	9973	10081	9973
query12	124	86	84	84
query13	1628	366	362	362
query14	10046	6873	6240	6240
query15	219	206	183	183
query16	7251	272	263	263
query17	1419	535	512	512
query18	1879	271	267	267
query19	191	147	154	147
query20	87	82	82	82
query21	220	129	126	126
query22	4397	4013	4039	4013
query23	33843	33701	33709	33701
query24	11273	2964	2892	2892
query25	605	395	411	395
query26	705	155	154	154
query27	2219	328	336	328
query28	6271	2207	2201	2201
query29	894	623	623	623
query30	273	158	162	158
query31	969	779	774	774
query32	92	54	60	54
query33	710	296	282	282
query34	965	474	485	474
query35	756	630	617	617
query36	1126	985	997	985
query37	153	81	80	80
query38	2937	2872	2778	2778
query39	888	817	845	817
query40	223	132	138	132
query41	55	54	53	53
query42	127	103	106	103
query43	601	540	560	540
query44	1167	746	760	746
query45	193	158	167	158
query46	1072	761	715	715
query47	1817	1769	1818	1769
query48	390	297	304	297
query49	846	426	417	417
query50	783	389	388	388
query51	6867	6765	6778	6765
query52	111	94	96	94
query53	363	297	297	297
query54	857	452	443	443
query55	80	73	78	73
query56	284	261	263	261
query57	1151	1021	1023	1021
query58	272	243	266	243
query59	3373	3238	3144	3144
query60	308	311	274	274
query61	97	123	89	89
query62	605	434	441	434
query63	317	287	298	287
query64	8877	2250	1715	1715
query65	3194	3086	3109	3086
query66	834	331	327	327
query67	15454	14926	14830	14830
query68	4574	549	549	549
query69	601	470	413	413
query70	1168	1142	1161	1142
query71	456	282	286	282
query72	7845	5608	2745	2745
query73	756	323	324	323
query74	5896	5518	5463	5463
query75	3372	2663	2686	2663
query76	2577	949	932	932
query77	596	305	299	299
query78	10415	9844	9592	9592
query79	2887	528	525	525
query80	2024	525	475	475
query81	586	225	218	218
query82	764	104	105	104
query83	327	173	181	173
query84	268	86	91	86
query85	1546	277	278	277
query86	475	333	312	312
query87	3265	3047	3091	3047
query88	4500	2392	2365	2365
query89	482	385	389	385
query90	1719	188	189	188
query91	131	100	98	98
query92	57	49	47	47
query93	4094	531	522	522
query94	1118	195	191	191
query95	408	315	315	315
query96	605	271	270	270
query97	3276	3108	3098	3098
query98	225	204	197	197
query99	1312	836	828	828
Total cold run time: 274700 ms
Total hot run time: 170631 ms

@doris-robot
Copy link

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

query1	0.04	0.04	0.04
query2	0.08	0.04	0.04
query3	0.22	0.05	0.05
query4	1.68	0.08	0.07
query5	0.50	0.50	0.49
query6	1.14	0.72	0.73
query7	0.02	0.01	0.02
query8	0.05	0.05	0.05
query9	0.55	0.50	0.50
query10	0.54	0.52	0.55
query11	0.15	0.12	0.12
query12	0.15	0.12	0.13
query13	0.59	0.60	0.60
query14	0.79	0.78	0.78
query15	0.85	0.82	0.83
query16	0.37	0.37	0.37
query17	1.03	1.06	1.02
query18	0.25	0.24	0.26
query19	1.81	1.74	1.74
query20	0.01	0.01	0.01
query21	15.45	0.72	0.64
query22	4.43	6.71	2.00
query23	18.30	1.35	1.24
query24	2.10	0.22	0.21
query25	0.15	0.07	0.10
query26	0.26	0.18	0.17
query27	0.08	0.09	0.09
query28	13.30	1.01	0.99
query29	12.65	3.25	3.28
query30	0.25	0.06	0.05
query31	2.86	0.39	0.38
query32	3.28	0.47	0.48
query33	2.85	2.88	2.97
query34	17.03	4.46	4.47
query35	4.64	4.49	4.45
query36	0.66	0.47	0.49
query37	0.18	0.15	0.16
query38	0.16	0.15	0.14
query39	0.04	0.03	0.04
query40	0.17	0.14	0.15
query41	0.08	0.04	0.04
query42	0.06	0.05	0.05
query43	0.04	0.04	0.04
Total cold run time: 109.84 s
Total hot run time: 30.72 s

@morrySnow
Copy link
Contributor

run p0

morrySnow
morrySnow previously approved these changes Jul 2, 2024
Copy link
Contributor

github-actions bot commented Jul 2, 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 Jul 2, 2024
@keanji-x
Copy link
Contributor Author

keanji-x commented Jul 3, 2024

run buildall

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

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

------ Round 1 ----------------------------------
q1	17626	4298	4222	4222
q2	2019	202	198	198
q3	10424	1249	1059	1059
q4	10196	745	785	745
q5	7485	2621	2622	2621
q6	215	135	136	135
q7	943	592	608	592
q8	9224	2045	2043	2043
q9	9032	6435	6435	6435
q10	9042	3674	3701	3674
q11	479	233	237	233
q12	473	240	236	236
q13	18781	2929	2975	2929
q14	273	224	242	224
q15	528	489	494	489
q16	534	375	375	375
q17	961	632	695	632
q18	7973	7356	7332	7332
q19	4481	1418	1464	1418
q20	656	315	330	315
q21	4968	3112	3223	3112
q22	389	334	343	334
Total cold run time: 116702 ms
Total hot run time: 39353 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4351	4240	4227	4227
q2	372	272	272	272
q3	3017	2757	2891	2757
q4	2000	1727	1671	1671
q5	5650	5573	5464	5464
q6	234	129	128	128
q7	2174	1787	1861	1787
q8	3274	3422	3395	3395
q9	8708	8685	8775	8685
q10	4096	3922	3752	3752
q11	583	488	494	488
q12	811	660	650	650
q13	15965	3157	3224	3157
q14	312	273	277	273
q15	541	503	504	503
q16	516	445	441	441
q17	1805	1536	1539	1536
q18	8030	8026	8094	8026
q19	2706	1677	1585	1585
q20	2114	1916	1836	1836
q21	5250	5071	4860	4860
q22	604	536	571	536
Total cold run time: 73113 ms
Total hot run time: 56029 ms

@doris-robot
Copy link

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

query1	934	385	370	370
query2	6476	2437	2424	2424
query3	6643	209	218	209
query4	19534	18306	18041	18041
query5	4286	496	536	496
query6	1543	189	159	159
query7	5781	307	315	307
query8	759	310	296	296
query9	10772	2406	2383	2383
query10	1449	335	360	335
query11	10508	10084	9972	9972
query12	115	84	83	83
query13	1748	384	375	375
query14	10473	7866	7171	7171
query15	258	196	191	191
query16	7990	275	263	263
query17	1940	527	522	522
query18	1940	281	271	271
query19	321	153	156	153
query20	88	83	81	81
query21	221	154	130	130
query22	4258	3932	3935	3932
query23	34294	33698	33581	33581
query24	10369	2887	2863	2863
query25	570	399	376	376
query26	702	151	151	151
query27	2119	322	335	322
query28	6243	2179	2134	2134
query29	881	629	631	629
query30	256	159	160	159
query31	994	750	746	746
query32	96	56	55	55
query33	674	295	300	295
query34	919	486	483	483
query35	756	660	637	637
query36	1162	982	1004	982
query37	142	75	82	75
query38	2948	2798	2785	2785
query39	910	826	790	790
query40	212	133	123	123
query41	52	58	54	54
query42	122	103	99	99
query43	583	537	536	536
query44	1073	750	738	738
query45	199	169	164	164
query46	1074	714	724	714
query47	1842	1756	1760	1756
query48	371	304	298	298
query49	826	408	420	408
query50	768	385	388	385
query51	6909	6815	6683	6683
query52	108	91	96	91
query53	368	296	283	283
query54	835	454	440	440
query55	73	74	74	74
query56	283	258	261	258
query57	1128	1106	1072	1072
query58	235	242	275	242
query59	3472	3231	3250	3231
query60	306	285	277	277
query61	93	94	95	94
query62	606	453	443	443
query63	322	291	295	291
query64	8489	2280	1818	1818
query65	3159	3100	3123	3100
query66	751	334	332	332
query67	15142	14947	14911	14911
query68	4533	546	556	546
query69	528	320	317	317
query70	1161	1144	1186	1144
query71	402	279	272	272
query72	7001	5477	5689	5477
query73	756	326	329	326
query74	5933	5519	5489	5489
query75	3455	2617	2714	2617
query76	2810	956	913	913
query77	430	309	307	307
query78	10394	9797	9849	9797
query79	2452	524	511	511
query80	959	474	496	474
query81	569	224	221	221
query82	771	109	105	105
query83	269	167	170	167
query84	244	88	84	84
query85	1720	275	276	275
query86	469	314	340	314
query87	3235	3092	3071	3071
query88	4394	2453	2447	2447
query89	466	373	376	373
query90	1752	196	188	188
query91	128	104	159	104
query92	58	47	47	47
query93	2176	512	516	512
query94	1044	189	195	189
query95	404	323	320	320
query96	605	272	276	272
query97	3176	2966	2984	2966
query98	219	190	195	190
query99	1155	824	812	812
Total cold run time: 275141 ms
Total hot run time: 174989 ms

@doris-robot
Copy link

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

query1	0.04	0.03	0.03
query2	0.07	0.04	0.04
query3	0.22	0.05	0.05
query4	1.67	0.10	0.08
query5	0.50	0.48	0.48
query6	1.13	0.72	0.72
query7	0.02	0.01	0.01
query8	0.05	0.04	0.05
query9	0.54	0.49	0.49
query10	0.56	0.53	0.54
query11	0.15	0.12	0.11
query12	0.15	0.12	0.12
query13	0.59	0.60	0.58
query14	0.77	0.79	0.78
query15	0.84	0.82	0.81
query16	0.36	0.39	0.38
query17	0.97	1.04	1.03
query18	0.23	0.26	0.23
query19	1.76	1.67	1.70
query20	0.02	0.01	0.01
query21	15.43	0.74	0.66
query22	4.16	7.40	1.87
query23	18.30	1.40	1.32
query24	2.19	0.22	0.23
query25	0.16	0.09	0.09
query26	0.27	0.17	0.17
query27	0.08	0.08	0.08
query28	13.21	1.01	1.00
query29	12.57	3.23	3.25
query30	0.25	0.07	0.05
query31	2.87	0.39	0.39
query32	3.28	0.49	0.47
query33	2.87	2.88	2.92
query34	16.84	4.42	4.42
query35	4.48	4.50	4.41
query36	0.66	0.46	0.46
query37	0.18	0.15	0.16
query38	0.15	0.15	0.14
query39	0.04	0.03	0.03
query40	0.17	0.13	0.15
query41	0.10	0.05	0.05
query42	0.07	0.04	0.04
query43	0.05	0.04	0.04
Total cold run time: 109.02 s
Total hot run time: 30.49 s

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

github-actions bot commented Jul 3, 2024

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

@morrySnow morrySnow merged commit 77233b5 into apache:master Jul 3, 2024
26 of 28 checks passed
morrySnow pushed a commit that referenced this pull request Jul 5, 2024
…eliminate fail (#36888)

this depends on 
#36839
#36886

Such as low level materialized view contains 5 group by dimension, and
query also has 5 group by dimension, they are equals.In this scene,
would not add aggregate on mv when try to rewrite query by materialized
view.
But if query only use 4 group by dimension and the remain demension is
can be eliminated, then the query will change to 4 group by dimension.
this will cause add aggregate on mv and will cause high level
materialize rewrite fail later.

Solution:
in aggregate rewrite by materialized view, we try to eliminate mv group
by dimension by query used dimension. if eliminate successfully. then
high level will rewrite continue.


such as 
low level mv def sql is as following:

    def join_mv_1 = """
        select l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, cast(sum(IFNULL(o_orderkey, 0) * IFNULL(o_custkey, 0)) as decimal(28, 8)) as agg1,
        sum(o_totalprice) as sum_total, 
        max(o_totalprice) as max_total, 
        min(o_totalprice) as min_total, 
        count(*) as count_all, 
        bitmap_union(to_bitmap(case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)) cnt_1, 
        bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as cnt_2 
        from lineitem_1
        inner join orders_1
        on lineitem_1.l_orderkey = orders_1.o_orderkey
        where lineitem_1.l_shipdate >= "2023-10-17"
        group by l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey
        """
    def join_mv_2 = """
        select l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, ps_partkey, ps_suppkey,
        t.agg1 as agg1, 
        t.sum_total as agg3,
        t.max_total as agg4,
        t.min_total as agg5,
        t.count_all as agg6,
        cast(sum(IFNULL(ps_suppkey, 0) * IFNULL(ps_partkey, 0)) as decimal(28, 8)) as agg2
        from ${mv_1} as t
        inner join partsupp_1
        on t.l_partkey = partsupp_1.ps_partkey and t.l_suppkey = partsupp_1.ps_suppkey
        where partsupp_1.ps_suppkey > 1
        group by l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, ps_partkey, ps_suppkey, agg1, agg3, agg4, agg5, agg6
        """

high level mv def sql is as following:

 def join_mv_3 = """
        select t1.l_orderkey, t2.l_partkey, t1.l_suppkey, t2.o_orderkey, t1.o_custkey, t2.ps_partkey, t1.ps_suppkey, t2.agg1, >t1.agg2, t2.agg3, t1.agg4, t2.agg5, t1.agg6 
        from ${mv_2} as t1
        left join ${mv_2} as t2
        on t1.l_orderkey = t2.l_orderkey
        where t1.l_orderkey > 1
        group by t1.l_orderkey, t2.l_partkey, t1.l_suppkey, t2.o_orderkey, t1.o_custkey, t2.ps_partkey, t1.ps_suppkey, >t2.agg1, >t1.agg2, t2.agg3, t1.agg4, t2.agg5, t1.agg6
        """

if we run the query as following, it can hit the mv3

select t1.l_orderkey, t2.l_partkey, t1.l_suppkey, t2.o_orderkey, t1.o_custkey, t2.ps_partkey, t1.ps_suppkey, t2.agg1, >t1.agg2, >t2.agg3, t1.agg4, t2.agg5, t1.agg6 
        from (
            select l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, ps_partkey, ps_suppkey, 
            t.agg1 as agg1, 
            t.sum_total as agg3,
            t.max_total as agg4,
            t.min_total as agg5,
            t.count_all as agg6,
            cast(sum(IFNULL(ps_suppkey, 0) * IFNULL(ps_partkey, 0)) as decimal(28, 8)) as agg2
            from (
                select l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, cast(sum(IFNULL(o_orderkey, 0) * >IFNULL(o_custkey, 0)) as decimal(28, 8)) as agg1,
                sum(o_totalprice) as sum_total, 
                max(o_totalprice) as max_total, 
                min(o_totalprice) as min_total, 
                count(*) as count_all, 
                bitmap_union(to_bitmap(case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)) >cnt_1, 
                bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as >cnt_2 
                from lineitem_1
                inner join orders_1
                on lineitem_1.l_orderkey = orders_1.o_orderkey
                where lineitem_1.l_shipdate >= "2023-10-17"
                group by l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey
            ) as t
            inner join partsupp_1
            on t.l_partkey = partsupp_1.ps_partkey and t.l_suppkey = partsupp_1.ps_suppkey
            where partsupp_1.ps_suppkey > 1
            group by l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, ps_partkey, ps_suppkey, agg1, agg3, agg4, >agg5, >agg6
        ) as t1
        left join (
            select l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, ps_partkey, ps_suppkey, 
            t.agg1 as agg1, 
            t.sum_total as agg3,
            t.max_total as agg4,
            t.min_total as agg5,
            t.count_all as agg6,
            cast(sum(IFNULL(ps_suppkey, 0) * IFNULL(ps_partkey, 0)) as decimal(28, 8)) as agg2
            from (
                select l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, cast(sum(IFNULL(o_orderkey, 0) * >IFNULL(o_custkey, 0)) as decimal(28, 8)) as agg1,
                sum(o_totalprice) as sum_total, 
                max(o_totalprice) as max_total, 
                min(o_totalprice) as min_total, 
                count(*) as count_all, 
                bitmap_union(to_bitmap(case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)) >cnt_1, 
                bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as >cnt_2 
                from lineitem_1
                inner join orders_1
                on lineitem_1.l_orderkey = orders_1.o_orderkey
                where lineitem_1.l_shipdate >= "2023-10-17"
                group by l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey
            ) as t
            inner join partsupp_1
            on t.l_partkey = partsupp_1.ps_partkey and t.l_suppkey = partsupp_1.ps_suppkey
            where partsupp_1.ps_suppkey > 1
            group by l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, ps_partkey, ps_suppkey, agg1, agg3, agg4, agg5, >agg6
        ) as t2
        on t1.l_orderkey = t2.l_orderkey
        where t1.l_orderkey > 1
        group by t1.l_orderkey, t2.l_partkey, t1.l_suppkey, t2.o_orderkey, t1.o_custkey, t2.ps_partkey, t1.ps_suppkey, >t2.agg1, >t1.agg2, t2.agg3, t1.agg4, t2.agg5, t1.agg6

---------

Co-authored-by: xiejiann <[email protected]>
dataroaring pushed a commit that referenced this pull request Jul 17, 2024
To avoid replacing slots in each data trait repeatedly, we split the
replace function into four functions and replaced them separately.
dataroaring pushed a commit that referenced this pull request Jul 17, 2024
…eliminate fail (#36888)

this depends on 
#36839
#36886

Such as low level materialized view contains 5 group by dimension, and
query also has 5 group by dimension, they are equals.In this scene,
would not add aggregate on mv when try to rewrite query by materialized
view.
But if query only use 4 group by dimension and the remain demension is
can be eliminated, then the query will change to 4 group by dimension.
this will cause add aggregate on mv and will cause high level
materialize rewrite fail later.

Solution:
in aggregate rewrite by materialized view, we try to eliminate mv group
by dimension by query used dimension. if eliminate successfully. then
high level will rewrite continue.


such as 
low level mv def sql is as following:

    def join_mv_1 = """
        select l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, cast(sum(IFNULL(o_orderkey, 0) * IFNULL(o_custkey, 0)) as decimal(28, 8)) as agg1,
        sum(o_totalprice) as sum_total, 
        max(o_totalprice) as max_total, 
        min(o_totalprice) as min_total, 
        count(*) as count_all, 
        bitmap_union(to_bitmap(case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)) cnt_1, 
        bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as cnt_2 
        from lineitem_1
        inner join orders_1
        on lineitem_1.l_orderkey = orders_1.o_orderkey
        where lineitem_1.l_shipdate >= "2023-10-17"
        group by l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey
        """
    def join_mv_2 = """
        select l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, ps_partkey, ps_suppkey,
        t.agg1 as agg1, 
        t.sum_total as agg3,
        t.max_total as agg4,
        t.min_total as agg5,
        t.count_all as agg6,
        cast(sum(IFNULL(ps_suppkey, 0) * IFNULL(ps_partkey, 0)) as decimal(28, 8)) as agg2
        from ${mv_1} as t
        inner join partsupp_1
        on t.l_partkey = partsupp_1.ps_partkey and t.l_suppkey = partsupp_1.ps_suppkey
        where partsupp_1.ps_suppkey > 1
        group by l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, ps_partkey, ps_suppkey, agg1, agg3, agg4, agg5, agg6
        """

high level mv def sql is as following:

 def join_mv_3 = """
        select t1.l_orderkey, t2.l_partkey, t1.l_suppkey, t2.o_orderkey, t1.o_custkey, t2.ps_partkey, t1.ps_suppkey, t2.agg1, >t1.agg2, t2.agg3, t1.agg4, t2.agg5, t1.agg6 
        from ${mv_2} as t1
        left join ${mv_2} as t2
        on t1.l_orderkey = t2.l_orderkey
        where t1.l_orderkey > 1
        group by t1.l_orderkey, t2.l_partkey, t1.l_suppkey, t2.o_orderkey, t1.o_custkey, t2.ps_partkey, t1.ps_suppkey, >t2.agg1, >t1.agg2, t2.agg3, t1.agg4, t2.agg5, t1.agg6
        """

if we run the query as following, it can hit the mv3

select t1.l_orderkey, t2.l_partkey, t1.l_suppkey, t2.o_orderkey, t1.o_custkey, t2.ps_partkey, t1.ps_suppkey, t2.agg1, >t1.agg2, >t2.agg3, t1.agg4, t2.agg5, t1.agg6 
        from (
            select l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, ps_partkey, ps_suppkey, 
            t.agg1 as agg1, 
            t.sum_total as agg3,
            t.max_total as agg4,
            t.min_total as agg5,
            t.count_all as agg6,
            cast(sum(IFNULL(ps_suppkey, 0) * IFNULL(ps_partkey, 0)) as decimal(28, 8)) as agg2
            from (
                select l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, cast(sum(IFNULL(o_orderkey, 0) * >IFNULL(o_custkey, 0)) as decimal(28, 8)) as agg1,
                sum(o_totalprice) as sum_total, 
                max(o_totalprice) as max_total, 
                min(o_totalprice) as min_total, 
                count(*) as count_all, 
                bitmap_union(to_bitmap(case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)) >cnt_1, 
                bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as >cnt_2 
                from lineitem_1
                inner join orders_1
                on lineitem_1.l_orderkey = orders_1.o_orderkey
                where lineitem_1.l_shipdate >= "2023-10-17"
                group by l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey
            ) as t
            inner join partsupp_1
            on t.l_partkey = partsupp_1.ps_partkey and t.l_suppkey = partsupp_1.ps_suppkey
            where partsupp_1.ps_suppkey > 1
            group by l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, ps_partkey, ps_suppkey, agg1, agg3, agg4, >agg5, >agg6
        ) as t1
        left join (
            select l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, ps_partkey, ps_suppkey, 
            t.agg1 as agg1, 
            t.sum_total as agg3,
            t.max_total as agg4,
            t.min_total as agg5,
            t.count_all as agg6,
            cast(sum(IFNULL(ps_suppkey, 0) * IFNULL(ps_partkey, 0)) as decimal(28, 8)) as agg2
            from (
                select l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, cast(sum(IFNULL(o_orderkey, 0) * >IFNULL(o_custkey, 0)) as decimal(28, 8)) as agg1,
                sum(o_totalprice) as sum_total, 
                max(o_totalprice) as max_total, 
                min(o_totalprice) as min_total, 
                count(*) as count_all, 
                bitmap_union(to_bitmap(case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)) >cnt_1, 
                bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as >cnt_2 
                from lineitem_1
                inner join orders_1
                on lineitem_1.l_orderkey = orders_1.o_orderkey
                where lineitem_1.l_shipdate >= "2023-10-17"
                group by l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey
            ) as t
            inner join partsupp_1
            on t.l_partkey = partsupp_1.ps_partkey and t.l_suppkey = partsupp_1.ps_suppkey
            where partsupp_1.ps_suppkey > 1
            group by l_orderkey, l_partkey, l_suppkey, o_orderkey, o_custkey, ps_partkey, ps_suppkey, agg1, agg3, agg4, agg5, >agg6
        ) as t2
        on t1.l_orderkey = t2.l_orderkey
        where t1.l_orderkey > 1
        group by t1.l_orderkey, t2.l_partkey, t1.l_suppkey, t2.o_orderkey, t1.o_custkey, t2.ps_partkey, t1.ps_suppkey, >t2.agg1, >t1.agg2, t2.agg3, t1.agg4, t2.agg5, t1.agg6

---------

Co-authored-by: xiejiann <[email protected]>
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/3.0.1-merged not-merge/2.1 reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants