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) support partitionTopn for multi window exprs #38393

Merged
merged 6 commits into from
Aug 6, 2024

Conversation

xzj7019
Copy link
Contributor

@xzj7019 xzj7019 commented Jul 25, 2024

Support partitionTopn for multi window exprs.
If row_number exists, choose row_number with the minimal limit value; if not, choose others with the minimal limit value.
Example:

mysql> explain shape plan select * from (select row_number() over(partition by c1, c2 order by c3) as rn, rank() over(partition by c1 order by c3) as rk from push_down_multi_predicate_through_window_t) t where rn <= 1 and rk <= 1;

+----------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                  |
+----------------------------------------------------------------------------------+
| PhysicalResultSink                                                               |
| --PhysicalProject                                                                |
| ----filter((rk <= 1) and (rn <= 1))                                              |
| ------PhysicalWindow                                                             |
| --------PhysicalQuickSort[LOCAL_SORT]                                            |
| ----------PhysicalDistribute[DistributionSpecHash]                               |
| ------------PhysicalWindow                                                       |
| --------------PhysicalQuickSort[LOCAL_SORT]                                      |
| ----------------PhysicalDistribute[DistributionSpecHash]                         |
| ------------------PhysicalPartitionTopN                                          |
| --------------------PhysicalOlapScan[push_down_multi_predicate_through_window_t] |
+----------------------------------------------------------------------------------+

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

@xzj7019 xzj7019 marked this pull request as draft July 25, 2024 14:17
@xzj7019
Copy link
Contributor Author

xzj7019 commented Jul 25, 2024

run buildall

1 similar comment
@xzj7019
Copy link
Contributor Author

xzj7019 commented Jul 26, 2024

run buildall

@xzj7019 xzj7019 force-pushed the support_multi_partitionTopn branch from 7e65c5a to 29f6a0b Compare July 26, 2024 06:10
@xzj7019
Copy link
Contributor Author

xzj7019 commented Jul 26, 2024

run buildall

@xzj7019 xzj7019 force-pushed the support_multi_partitionTopn branch from 29f6a0b to 04ff675 Compare July 26, 2024 07:24
@xzj7019
Copy link
Contributor Author

xzj7019 commented Jul 26, 2024

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17844	4475	4376	4376
q2	2638	205	204	204
q3	11277	1195	1122	1122
q4	10753	671	698	671
q5	7548	2769	2751	2751
q6	223	141	141	141
q7	986	614	618	614
q8	9616	1913	1923	1913
q9	8858	6536	6502	6502
q10	8732	3746	3758	3746
q11	460	255	253	253
q12	396	228	226	226
q13	18298	2999	2988	2988
q14	297	237	232	232
q15	518	470	485	470
q16	483	381	380	380
q17	960	693	650	650
q18	8031	7421	7425	7421
q19	3408	988	881	881
q20	695	334	335	334
q21	5562	3284	3212	3212
q22	373	299	288	288
Total cold run time: 117956 ms
Total hot run time: 39375 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4342	4359	4232	4232
q2	379	288	272	272
q3	2975	2789	2735	2735
q4	1867	1645	1631	1631
q5	5306	5326	5332	5326
q6	221	140	133	133
q7	2142	1707	1781	1707
q8	3193	3324	3294	3294
q9	8454	8332	8389	8332
q10	3853	3692	3672	3672
q11	596	487	489	487
q12	764	592	596	592
q13	17360	2996	3017	2996
q14	304	301	277	277
q15	518	472	479	472
q16	473	421	410	410
q17	1750	1477	1476	1476
q18	7837	7558	7269	7269
q19	1837	1547	1656	1547
q20	2029	1815	1768	1768
q21	4891	4737	4595	4595
q22	585	500	509	500
Total cold run time: 71676 ms
Total hot run time: 53723 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 172696 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 04ff675c6fe179b4a9f48e49b1ce1f90b034c894, data reload: false

query1	915	372	363	363
query2	6443	1951	1884	1884
query3	6642	207	214	207
query4	28394	17597	17453	17453
query5	4219	492	513	492
query6	271	176	166	166
query7	4578	291	281	281
query8	237	207	190	190
query9	8460	2467	2441	2441
query10	424	277	262	262
query11	11734	10061	10163	10061
query12	134	88	83	83
query13	1615	374	368	368
query14	9433	7651	7680	7651
query15	234	168	164	164
query16	7725	497	492	492
query17	1600	557	518	518
query18	1912	287	297	287
query19	197	159	136	136
query20	93	84	84	84
query21	217	103	111	103
query22	4232	3929	3932	3929
query23	33577	33326	33074	33074
query24	12101	2979	2912	2912
query25	658	390	405	390
query26	1754	155	154	154
query27	2927	270	275	270
query28	7710	2039	1998	1998
query29	1038	404	408	404
query30	287	150	151	150
query31	944	730	743	730
query32	97	51	54	51
query33	778	331	324	324
query34	893	467	469	467
query35	861	741	738	738
query36	1093	936	906	906
query37	287	84	81	81
query38	2846	2733	2766	2733
query39	848	828	809	809
query40	263	136	112	112
query41	49	44	49	44
query42	124	100	104	100
query43	502	474	478	474
query44	1247	715	719	715
query45	210	180	179	179
query46	1098	736	729	729
query47	1819	1744	1761	1744
query48	359	295	304	295
query49	1191	416	419	416
query50	812	416	418	416
query51	6795	6598	6646	6598
query52	111	86	92	86
query53	256	180	181	180
query54	1012	440	439	439
query55	75	74	72	72
query56	297	275	281	275
query57	1139	1061	1023	1023
query58	260	261	266	261
query59	3042	2747	2745	2745
query60	351	281	295	281
query61	98	95	94	94
query62	839	640	654	640
query63	213	186	183	183
query64	10523	2292	1744	1744
query65	3191	3116	3160	3116
query66	1365	334	329	329
query67	15308	14719	14703	14703
query68	4584	540	557	540
query69	432	327	296	296
query70	1172	1054	1102	1054
query71	406	283	271	271
query72	7030	5889	5920	5889
query73	756	337	335	335
query74	6014	5706	5654	5654
query75	3386	2677	2695	2677
query76	2705	929	870	870
query77	465	305	299	299
query78	10149	9020	8871	8871
query79	2664	522	507	507
query80	2492	486	497	486
query81	593	218	218	218
query82	873	142	136	136
query83	308	174	176	174
query84	266	89	79	79
query85	2148	375	302	302
query86	492	301	311	301
query87	3243	3072	3071	3071
query88	4142	2489	2470	2470
query89	394	282	283	282
query90	1849	197	198	197
query91	133	101	109	101
query92	64	47	47	47
query93	3404	532	534	532
query94	813	299	279	279
query95	359	263	264	263
query96	618	277	273	273
query97	3181	2966	2984	2966
query98	222	203	199	199
query99	1556	1258	1271	1258
Total cold run time: 287870 ms
Total hot run time: 172696 ms

@doris-robot
Copy link

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

query1	0.04	0.04	0.04
query2	0.08	0.04	0.04
query3	0.23	0.06	0.05
query4	1.64	0.09	0.10
query5	0.49	0.49	0.48
query6	1.13	0.73	0.71
query7	0.02	0.01	0.01
query8	0.05	0.04	0.04
query9	0.55	0.50	0.49
query10	0.55	0.55	0.55
query11	0.16	0.11	0.11
query12	0.15	0.12	0.12
query13	0.60	0.58	0.59
query14	0.75	0.77	0.78
query15	0.86	0.81	0.81
query16	0.38	0.37	0.37
query17	1.04	1.04	1.03
query18	0.23	0.22	0.23
query19	1.86	1.77	1.71
query20	0.01	0.00	0.00
query21	15.40	0.78	0.65
query22	4.83	6.71	1.96
query23	18.28	1.45	1.22
query24	2.12	0.23	0.22
query25	0.16	0.09	0.08
query26	0.29	0.21	0.21
query27	0.46	0.24	0.22
query28	13.28	1.02	1.00
query29	12.66	3.36	3.36
query30	0.25	0.06	0.05
query31	2.86	0.39	0.38
query32	3.26	0.48	0.47
query33	2.90	2.86	2.95
query34	17.09	4.34	4.34
query35	4.42	4.43	4.48
query36	0.65	0.49	0.47
query37	0.20	0.15	0.16
query38	0.15	0.15	0.14
query39	0.04	0.04	0.03
query40	0.15	0.13	0.13
query41	0.09	0.06	0.06
query42	0.06	0.05	0.05
query43	0.04	0.05	0.04
Total cold run time: 110.46 s
Total hot run time: 30.74 s

@xzj7019 xzj7019 marked this pull request as ready for review July 26, 2024 11:49
@xzj7019
Copy link
Contributor Author

xzj7019 commented Jul 26, 2024

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	18051	4403	4388	4388
q2	3028	203	201	201
q3	11252	1224	1158	1158
q4	10531	785	740	740
q5	7523	2774	2694	2694
q6	224	142	141	141
q7	993	603	609	603
q8	9610	1892	1921	1892
q9	8673	6567	6587	6567
q10	8700	3787	3762	3762
q11	484	259	254	254
q12	396	227	223	223
q13	17753	2967	2989	2967
q14	271	232	245	232
q15	514	486	489	486
q16	502	390	387	387
q17	963	707	710	707
q18	8011	7450	7462	7450
q19	4031	1096	1052	1052
q20	677	339	321	321
q21	5001	3259	3224	3224
q22	350	289	288	288
Total cold run time: 117538 ms
Total hot run time: 39737 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4406	4226	4267	4226
q2	369	271	267	267
q3	3000	2780	2792	2780
q4	1901	1632	1622	1622
q5	5301	5286	5302	5286
q6	215	132	134	132
q7	2142	1749	1750	1749
q8	3180	3341	3316	3316
q9	8389	8390	8389	8389
q10	3878	3708	3711	3708
q11	570	477	488	477
q12	750	600	593	593
q13	16693	2950	3003	2950
q14	308	274	304	274
q15	513	472	482	472
q16	475	421	414	414
q17	1783	1480	1457	1457
q18	7647	7487	7233	7233
q19	1724	1600	1490	1490
q20	2019	1810	1754	1754
q21	4779	4823	4557	4557
q22	570	485	505	485
Total cold run time: 70612 ms
Total hot run time: 53631 ms

@doris-robot
Copy link

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

query1	915	366	374	366
query2	6448	2002	1879	1879
query3	6652	209	214	209
query4	28824	17391	17506	17391
query5	4202	482	498	482
query6	266	170	156	156
query7	4581	293	291	291
query8	230	191	190	190
query9	8612	2465	2449	2449
query10	454	307	281	281
query11	11556	10059	10133	10059
query12	145	88	85	85
query13	1630	376	377	376
query14	9484	7785	7769	7769
query15	220	166	167	166
query16	7729	474	492	474
query17	1573	586	521	521
query18	1957	282	278	278
query19	189	145	142	142
query20	92	84	81	81
query21	210	99	121	99
query22	4199	3981	3920	3920
query23	34101	33017	33280	33017
query24	11110	2854	2936	2854
query25	640	386	374	374
query26	1423	153	148	148
query27	2899	280	273	273
query28	7708	2009	1993	1993
query29	949	410	407	407
query30	288	148	150	148
query31	971	745	754	745
query32	96	54	54	54
query33	792	328	322	322
query34	911	471	492	471
query35	854	740	766	740
query36	1116	950	902	902
query37	151	80	85	80
query38	2874	2776	2733	2733
query39	888	845	810	810
query40	262	121	115	115
query41	53	45	45	45
query42	117	97	106	97
query43	505	477	471	471
query44	1225	712	712	712
query45	215	177	176	176
query46	1102	730	732	730
query47	1843	1770	1786	1770
query48	362	300	327	300
query49	1097	408	420	408
query50	801	419	413	413
query51	6815	6690	6791	6690
query52	105	89	92	89
query53	254	179	184	179
query54	884	441	445	441
query55	76	75	76	75
query56	290	268	300	268
query57	1156	1041	1079	1041
query58	268	258	271	258
query59	2794	2651	2779	2651
query60	308	301	283	283
query61	96	128	98	98
query62	827	664	656	656
query63	223	181	180	180
query64	10532	2258	1697	1697
query65	3152	3141	3077	3077
query66	1371	334	341	334
query67	15649	15064	14715	14715
query68	4580	537	548	537
query69	498	305	309	305
query70	1082	1087	1144	1087
query71	395	277	278	277
query72	6966	5551	5678	5551
query73	740	334	333	333
query74	6166	5704	5676	5676
query75	3383	2709	2653	2653
query76	2524	970	923	923
query77	481	311	322	311
query78	11274	9837	9092	9092
query79	4674	530	530	530
query80	1853	489	488	488
query81	582	219	231	219
query82	1193	139	141	139
query83	321	175	178	175
query84	282	76	82	76
query85	907	317	320	317
query86	478	310	320	310
query87	3280	3181	3088	3088
query88	4811	2496	2502	2496
query89	436	298	291	291
query90	1885	214	202	202
query91	140	113	186	113
query92	61	52	51	51
query93	4430	535	530	530
query94	887	297	289	289
query95	354	265	265	265
query96	619	278	272	272
query97	3228	3042	3047	3042
query98	229	202	199	199
query99	1643	1249	1268	1249
Total cold run time: 290703 ms
Total hot run time: 172790 ms

@doris-robot
Copy link

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

query1	0.04	0.03	0.03
query2	0.08	0.04	0.04
query3	0.23	0.05	0.06
query4	1.67	0.08	0.08
query5	0.50	0.49	0.48
query6	1.13	0.74	0.73
query7	0.02	0.02	0.02
query8	0.05	0.04	0.04
query9	0.55	0.50	0.48
query10	0.53	0.55	0.54
query11	0.16	0.11	0.12
query12	0.15	0.12	0.12
query13	0.60	0.58	0.58
query14	0.76	0.80	0.78
query15	0.85	0.81	0.81
query16	0.37	0.35	0.36
query17	0.96	0.97	1.03
query18	0.23	0.22	0.22
query19	1.82	1.67	1.70
query20	0.01	0.01	0.01
query21	15.39	0.76	0.64
query22	4.65	6.00	2.72
query23	18.31	1.42	1.32
query24	2.06	0.24	0.23
query25	0.15	0.09	0.08
query26	0.31	0.21	0.22
query27	0.45	0.23	0.24
query28	13.23	1.02	1.01
query29	12.60	3.27	3.24
query30	0.25	0.06	0.06
query31	2.86	0.40	0.39
query32	3.28	0.47	0.47
query33	2.87	2.95	2.88
query34	17.06	4.36	4.37
query35	4.39	4.42	4.41
query36	0.65	0.46	0.48
query37	0.18	0.15	0.15
query38	0.16	0.14	0.15
query39	0.04	0.04	0.03
query40	0.16	0.13	0.12
query41	0.09	0.04	0.05
query42	0.05	0.04	0.05
query43	0.04	0.04	0.04
Total cold run time: 109.94 s
Total hot run time: 31.38 s

@xzj7019
Copy link
Contributor Author

xzj7019 commented Jul 28, 2024

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17675	4335	4279	4279
q2	2022	200	193	193
q3	10448	1189	1119	1119
q4	10148	703	713	703
q5	7544	2729	2598	2598
q6	215	135	136	135
q7	959	599	603	599
q8	9233	1909	1930	1909
q9	8808	6568	6540	6540
q10	8804	3789	3780	3780
q11	449	248	254	248
q12	438	226	221	221
q13	17772	2998	2970	2970
q14	280	237	241	237
q15	514	489	496	489
q16	499	400	384	384
q17	979	659	683	659
q18	8042	7505	7460	7460
q19	4256	979	972	972
q20	679	336	331	331
q21	5023	3271	3273	3271
q22	350	297	288	288
Total cold run time: 115137 ms
Total hot run time: 39385 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4376	4208	4229	4208
q2	354	265	276	265
q3	3168	2747	2794	2747
q4	1995	1762	1760	1760
q5	5577	5591	5515	5515
q6	228	143	135	135
q7	2178	1798	1781	1781
q8	3299	3459	3384	3384
q9	8834	8752	8912	8752
q10	4171	3872	3841	3841
q11	571	477	489	477
q12	825	643	627	627
q13	15889	3197	3111	3111
q14	326	284	284	284
q15	535	493	496	493
q16	486	454	432	432
q17	1813	1533	1510	1510
q18	8114	7960	7958	7958
q19	1749	1607	1516	1516
q20	2057	1926	1856	1856
q21	5206	4915	4811	4811
q22	589	516	497	497
Total cold run time: 72340 ms
Total hot run time: 55960 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 173456 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 303158a26f2d04939dca91a69f787f08d773b84a, data reload: false

query1	907	368	368	368
query2	6433	1956	1894	1894
query3	6627	206	214	206
query4	28340	17562	17432	17432
query5	3652	471	475	471
query6	267	184	172	172
query7	4578	298	290	290
query8	261	203	189	189
query9	8546	2469	2448	2448
query10	442	297	271	271
query11	11952	10065	10138	10065
query12	115	88	86	86
query13	1618	386	373	373
query14	10085	7667	7645	7645
query15	237	174	170	170
query16	7685	520	496	496
query17	1619	564	552	552
query18	1996	293	288	288
query19	194	150	147	147
query20	93	83	83	83
query21	207	106	101	101
query22	4338	4087	3833	3833
query23	34051	33724	33635	33635
query24	11108	2921	2949	2921
query25	626	413	424	413
query26	717	161	161	161
query27	2317	292	293	292
query28	6408	2117	2115	2115
query29	837	448	468	448
query30	274	160	156	156
query31	991	778	773	773
query32	97	55	62	55
query33	784	354	425	354
query34	860	486	488	486
query35	864	737	748	737
query36	1112	987	939	939
query37	140	88	83	83
query38	3065	2873	2797	2797
query39	916	873	859	859
query40	199	118	113	113
query41	46	47	42	42
query42	120	98	106	98
query43	510	457	485	457
query44	1238	726	724	724
query45	211	174	184	174
query46	1098	735	748	735
query47	1839	1748	1789	1748
query48	363	292	295	292
query49	852	414	418	414
query50	793	402	423	402
query51	6762	6711	6717	6711
query52	102	87	91	87
query53	248	183	183	183
query54	879	455	452	452
query55	77	76	76	76
query56	295	267	274	267
query57	1128	1055	1051	1051
query58	258	258	269	258
query59	2993	2922	2598	2598
query60	309	309	287	287
query61	99	99	98	98
query62	804	645	650	645
query63	205	177	182	177
query64	9270	2278	1741	1741
query65	3183	3116	3084	3084
query66	730	332	325	325
query67	15519	14731	14670	14670
query68	8458	581	570	570
query69	701	422	335	335
query70	1140	1103	1017	1017
query71	523	281	284	281
query72	9142	5500	5837	5500
query73	1236	337	333	333
query74	6179	5623	5673	5623
query75	5062	2654	2708	2654
query76	5178	1008	897	897
query77	813	320	301	301
query78	9638	9018	8955	8955
query79	6916	550	535	535
query80	1312	511	553	511
query81	576	216	222	216
query82	796	141	138	138
query83	299	181	177	177
query84	268	82	83	82
query85	1347	326	308	308
query86	402	306	318	306
query87	3234	3068	3050	3050
query88	4307	2480	2477	2477
query89	428	292	291	291
query90	1934	204	198	198
query91	129	104	104	104
query92	64	48	52	48
query93	5202	555	549	549
query94	837	286	299	286
query95	362	270	260	260
query96	612	282	275	275
query97	3257	3025	3011	3011
query98	223	200	203	200
query99	1506	1264	1255	1255
Total cold run time: 297570 ms
Total hot run time: 173456 ms

@doris-robot
Copy link

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

query1	0.04	0.03	0.04
query2	0.08	0.03	0.04
query3	0.23	0.05	0.05
query4	1.68	0.08	0.08
query5	0.50	0.49	0.49
query6	1.13	0.73	0.73
query7	0.02	0.02	0.02
query8	0.05	0.04	0.04
query9	0.54	0.48	0.49
query10	0.53	0.53	0.55
query11	0.15	0.11	0.12
query12	0.15	0.12	0.13
query13	0.61	0.60	0.58
query14	0.75	0.79	0.76
query15	0.86	0.81	0.82
query16	0.38	0.37	0.37
query17	1.01	1.04	1.05
query18	0.23	0.21	0.22
query19	1.92	1.80	1.80
query20	0.01	0.00	0.00
query21	15.38	0.78	0.65
query22	3.95	8.31	1.58
query23	18.29	1.50	1.31
query24	2.11	0.22	0.22
query25	0.16	0.08	0.08
query26	0.31	0.21	0.22
query27	0.45	0.24	0.23
query28	13.37	1.03	0.98
query29	12.60	3.31	3.27
query30	0.25	0.06	0.06
query31	2.87	0.40	0.39
query32	3.26	0.48	0.47
query33	2.92	2.93	2.98
query34	16.98	4.34	4.35
query35	4.45	4.41	4.38
query36	0.65	0.46	0.48
query37	0.19	0.15	0.16
query38	0.16	0.15	0.15
query39	0.04	0.04	0.03
query40	0.17	0.13	0.12
query41	0.10	0.04	0.05
query42	0.05	0.05	0.04
query43	0.04	0.04	0.04
Total cold run time: 109.62 s
Total hot run time: 30.41 s

@englefly
Copy link
Contributor

please add a sql example in "Proposed changes" section

@xzj7019
Copy link
Contributor Author

xzj7019 commented Jul 29, 2024

please add a sql example in "Proposed changes" section

Done

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

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

Copy link
Contributor

PR approved by anyone and no changes requested.

* pushPartitionLimitThroughWindow is used to push the partitionLimit through the window
* and generate the partitionTopN. If the window can not meet the requirement,
* it will return null. So when we use this function, we need check the null in the outside.
* check and get valid window function and partition limit value
Copy link
Contributor

Choose a reason for hiding this comment

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

add comment to explain the input parameter and return value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

long chosenRowNumberPartitionLimit = Long.MAX_VALUE;
boolean hasRowNumber = false;
for (NamedExpression windowExpr : windowExpressions) {
WindowExpression windowFunc = (WindowExpression) windowExpr.child(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

check before cast?

Copy link
Contributor Author

@xzj7019 xzj7019 Aug 5, 2024

Choose a reason for hiding this comment

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

done

Set<Expression> conjuncts = filter.getConjuncts();
Set<Expression> relatedConjuncts = extractRelatedConjuncts(conjuncts, windowExpr.getExprId());
for (Expression conjunct : relatedConjuncts) {
Preconditions.checkArgument(conjunct instanceof BinaryOperator);
Copy link
Contributor

Choose a reason for hiding this comment

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

add error msg? log warning log and return null instead throw exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove the pre-condition checking since the former logic has been done.

Comment on lines 251 to 252
Preconditions.checkArgument(leftChild instanceof SlotReference
&& rightChild instanceof IntegerLikeLiteral);
Copy link
Contributor

Choose a reason for hiding this comment

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

add error msg? log warning log and return null instead throw exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove the pre-condition checking since the former logic has been done.

@xzj7019 xzj7019 force-pushed the support_multi_partitionTopn branch from d053abc to 95c8ad6 Compare August 5, 2024 04:29
@xzj7019
Copy link
Contributor Author

xzj7019 commented Aug 5, 2024

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17642	4341	4090	4090
q2	2023	203	199	199
q3	10470	1330	1355	1330
q4	10181	854	923	854
q5	7668	2986	3016	2986
q6	224	142	140	140
q7	1073	618	608	608
q8	9445	1954	1988	1954
q9	8531	6652	6677	6652
q10	8788	3867	3881	3867
q11	433	254	254	254
q12	406	236	230	230
q13	17775	2939	2949	2939
q14	274	243	248	243
q15	523	490	490	490
q16	526	397	390	390
q17	992	926	949	926
q18	8064	7339	7237	7237
q19	1573	1227	1242	1227
q20	570	332	336	332
q21	5307	4717	4823	4717
q22	359	279	296	279
Total cold run time: 112847 ms
Total hot run time: 41944 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4141	4033	4043	4033
q2	332	234	223	223
q3	3033	3030	3163	3030
q4	2057	2045	2023	2023
q5	5646	5485	5426	5426
q6	217	136	138	136
q7	2123	1801	1800	1800
q8	3326	3385	3413	3385
q9	8751	8799	8807	8799
q10	3988	4073	3934	3934
q11	555	464	469	464
q12	781	609	608	608
q13	16405	3156	3131	3131
q14	316	282	274	274
q15	531	485	507	485
q16	467	420	410	410
q17	1778	1801	1714	1714
q18	8299	7825	7678	7678
q19	1793	1766	1748	1748
q20	2060	1846	1828	1828
q21	5667	5582	5479	5479
q22	528	465	474	465
Total cold run time: 72794 ms
Total hot run time: 57073 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 168646 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 95c8ad6fe3c9c889e4581d671391320e22b8cc82, data reload: false

query1	923	390	376	376
query2	6462	1740	1694	1694
query3	6651	219	225	219
query4	20010	17631	17040	17040
query5	3624	533	521	521
query6	289	168	156	156
query7	4601	317	293	293
query8	248	203	205	203
query9	8506	2394	2361	2361
query10	434	285	268	268
query11	10498	10010	9978	9978
query12	118	97	84	84
query13	1628	391	375	375
query14	9282	6932	6207	6207
query15	204	160	166	160
query16	6927	472	449	449
query17	943	544	550	544
query18	1914	279	283	279
query19	192	143	148	143
query20	97	86	88	86
query21	202	107	99	99
query22	4187	4128	3831	3831
query23	33632	33662	33525	33525
query24	10175	3130	3111	3111
query25	677	393	416	393
query26	1675	163	152	152
query27	2951	286	285	285
query28	7499	2057	2040	2040
query29	1265	441	456	441
query30	233	155	154	154
query31	953	750	754	750
query32	101	58	60	58
query33	674	317	322	317
query34	927	496	494	494
query35	854	782	771	771
query36	1053	896	910	896
query37	285	84	88	84
query38	3011	2865	2801	2801
query39	914	807	824	807
query40	253	112	111	111
query41	45	45	45	45
query42	115	103	103	103
query43	469	435	423	423
query44	1202	745	741	741
query45	214	191	185	185
query46	1091	823	790	790
query47	1786	1707	1742	1707
query48	364	293	293	293
query49	959	443	432	432
query50	912	438	442	438
query51	6783	6752	6708	6708
query52	105	88	90	88
query53	250	188	179	179
query54	648	455	446	446
query55	78	75	76	75
query56	273	256	253	253
query57	1144	1009	1038	1009
query58	287	268	279	268
query59	2618	2362	2517	2362
query60	297	280	279	279
query61	98	89	102	89
query62	890	673	666	666
query63	216	188	187	187
query64	5734	1935	1866	1866
query65	3167	3102	3111	3102
query66	1315	335	327	327
query67	15189	14796	14950	14796
query68	4255	580	581	580
query69	425	311	315	311
query70	1142	1093	1117	1093
query71	373	287	281	281
query72	7002	2672	2493	2493
query73	771	328	328	328
query74	6047	5679	5649	5649
query75	3379	2722	2745	2722
query76	2057	1241	1253	1241
query77	416	313	321	313
query78	9510	8857	8756	8756
query79	1762	538	542	538
query80	1425	511	513	511
query81	565	231	230	230
query82	1036	136	135	135
query83	252	166	177	166
query84	262	81	79	79
query85	1202	308	301	301
query86	412	300	300	300
query87	3269	3142	3151	3142
query88	2937	2419	2421	2419
query89	389	302	286	286
query90	1661	194	200	194
query91	128	100	101	100
query92	56	50	50	50
query93	1522	682	628	628
query94	788	298	317	298
query95	372	267	271	267
query96	598	287	282	282
query97	3259	3063	3074	3063
query98	217	196	193	193
query99	1613	1284	1307	1284
Total cold run time: 260423 ms
Total hot run time: 168646 ms

@doris-robot
Copy link

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

query1	0.05	0.04	0.03
query2	0.08	0.04	0.04
query3	0.23	0.05	0.05
query4	1.68	0.07	0.06
query5	0.49	0.48	0.47
query6	1.14	0.72	0.72
query7	0.02	0.02	0.01
query8	0.05	0.04	0.04
query9	0.58	0.50	0.52
query10	0.56	0.56	0.55
query11	0.15	0.12	0.12
query12	0.15	0.12	0.12
query13	0.61	0.60	0.60
query14	0.78	0.81	0.79
query15	0.90	0.86	0.86
query16	0.35	0.35	0.35
query17	0.99	0.98	1.00
query18	0.22	0.21	0.23
query19	1.80	1.71	1.85
query20	0.01	0.01	0.01
query21	15.41	0.76	0.67
query22	3.89	6.31	2.02
query23	17.93	1.29	1.21
query24	2.23	0.22	0.22
query25	0.17	0.09	0.07
query26	0.31	0.22	0.22
query27	0.46	0.24	0.23
query28	13.18	0.99	0.98
query29	12.60	3.34	3.30
query30	0.25	0.06	0.06
query31	2.92	0.41	0.40
query32	3.23	0.49	0.49
query33	2.96	2.93	2.99
query34	15.50	4.26	4.24
query35	4.27	4.26	4.29
query36	0.68	0.48	0.49
query37	0.19	0.17	0.16
query38	0.16	0.16	0.15
query39	0.04	0.04	0.04
query40	0.16	0.14	0.13
query41	0.10	0.04	0.05
query42	0.05	0.05	0.05
query43	0.05	0.04	0.04
Total cold run time: 107.58 s
Total hot run time: 30.61 s

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

github-actions bot commented Aug 6, 2024

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

@englefly englefly merged commit c7b4e48 into apache:master Aug 6, 2024
34 of 40 checks passed
dataroaring pushed a commit that referenced this pull request Aug 11, 2024
Support partitionTopn for multi window exprs.
If row_number exists, choose row_number with the minimal limit value; if
not, choose others with the minimal limit value.
Example:

```
mysql> explain shape plan select * from (select row_number() over(partition by c1, c2 order by c3) as rn, rank() over(partition by c1 order by c3) as rk from push_down_multi_predicate_through_window_t) t where rn <= 1 and rk <= 1;

+----------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                  |
+----------------------------------------------------------------------------------+
| PhysicalResultSink                                                               |
| --PhysicalProject                                                                |
| ----filter((rk <= 1) and (rn <= 1))                                              |
| ------PhysicalWindow                                                             |
| --------PhysicalQuickSort[LOCAL_SORT]                                            |
| ----------PhysicalDistribute[DistributionSpecHash]                               |
| ------------PhysicalWindow                                                       |
| --------------PhysicalQuickSort[LOCAL_SORT]                                      |
| ----------------PhysicalDistribute[DistributionSpecHash]                         |
| ------------------PhysicalPartitionTopN                                          |
| --------------------PhysicalOlapScan[push_down_multi_predicate_through_window_t] |
+----------------------------------------------------------------------------------+
```

---------

Co-authored-by: zhongjian.xzj <zhongjian.xzj@zhongjianxzjdeMacBook-Pro.local>
morrySnow pushed a commit that referenced this pull request Aug 13, 2024
intro by #38393

Fix the cases whose window function both contains row_number and other
types but only the other types contains pushing down filter.
wyxxxcat pushed a commit to wyxxxcat/doris that referenced this pull request Aug 14, 2024
…e#39233)

intro by apache#38393

Fix the cases whose window function both contains row_number and other
types but only the other types contains pushing down filter.
dataroaring pushed a commit that referenced this pull request Aug 16, 2024
Support partitionTopn for multi window exprs.
If row_number exists, choose row_number with the minimal limit value; if
not, choose others with the minimal limit value.
Example:

```
mysql> explain shape plan select * from (select row_number() over(partition by c1, c2 order by c3) as rn, rank() over(partition by c1 order by c3) as rk from push_down_multi_predicate_through_window_t) t where rn <= 1 and rk <= 1;

+----------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                  |
+----------------------------------------------------------------------------------+
| PhysicalResultSink                                                               |
| --PhysicalProject                                                                |
| ----filter((rk <= 1) and (rn <= 1))                                              |
| ------PhysicalWindow                                                             |
| --------PhysicalQuickSort[LOCAL_SORT]                                            |
| ----------PhysicalDistribute[DistributionSpecHash]                               |
| ------------PhysicalWindow                                                       |
| --------------PhysicalQuickSort[LOCAL_SORT]                                      |
| ----------------PhysicalDistribute[DistributionSpecHash]                         |
| ------------------PhysicalPartitionTopN                                          |
| --------------------PhysicalOlapScan[push_down_multi_predicate_through_window_t] |
+----------------------------------------------------------------------------------+
```

---------

Co-authored-by: zhongjian.xzj <zhongjian.xzj@zhongjianxzjdeMacBook-Pro.local>
dataroaring pushed a commit that referenced this pull request Aug 17, 2024
intro by #38393

Fix the cases whose window function both contains row_number and other
types but only the other types contains pushing down filter.
yiguolei pushed a commit that referenced this pull request Aug 22, 2024
## Proposed changes

pick from #38393

Co-authored-by: xiongzhongjian <xiongzhongjian@selectdb.com>
@yiguolei yiguolei mentioned this pull request Sep 5, 2024
3 tasks
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.6-merged dev/3.0.2-merged doing reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants