Skip to content

Conversation

@924060929
Copy link
Contributor

cherry pick from #54947

close apache#54577

optimize normalize window, only push down the expression's used slots to
bottom projects, which the expression not contains WindowFunction, so we
can push down more filter through window.

for this sql:
```sql
  select
    SUBSTR(orderdate,1,10) AS dt,
    ROW_NUMBER() OVER(PARTITION BY orderdate ORDER BY orderid DESC) AS rn
  from lineorders
  having dt = '2025-01-01'
```
we not push down the `dt` slot under LogicalWindow, but push down
[orderdate, orderid]
to the bottom projects, because if we push down `dt`, the plan tree will
be:
```
            LogicalFilter(substr(dt#3, 1, 10) = '2025-01-01')
                                    |
     LogicalWindow(rowNumber(partition by orderdate#2, order by orderid#1))
                                    |
  LogicalProject(orderid#1, orderdate#2, substr(orderdate#1, 1, 10) as dt#3)
```

and can not push down filter by `PushDownFilterThroughWindow`, causing
inefficiency,
because dt#3 in LogicalFilter not contains in the partition key in
LogicalWindow: [orderdate#2].

so we only push down orderdate in the LogicalFilter, not push down `dt`:

```
     LogicalFilter(substr(orderdate#2, 1, 10) = '2025-01-01')
                              |
     LogicalWindow(rowNumber(partition by orderdate#2, order by orderid#1))
                              |
            LogicalProject(orderid#1, orderdate#2)
```

and then, `PushDownFilterThroughWindow` found the LogicalFilter's
`orderdate#2` contains
in the LogicalWindow's partition key: [orderdate#2], and can push down
filter to:

```
  LogicalWindow(rowNumber(partition by orderdate#2, order by orderid#1))
                              |
            LogicalProject(orderid#1, orderdate#2)
                             |
    LogicalFilter(substr(orderdate#2, 1, 10) = '2025-01-01')
```

(cherry picked from commit 0e669b9)
@924060929 924060929 requested a review from dataroaring as a code owner August 20, 2025 04:52
@hello-stephen
Copy link
Contributor

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

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@924060929 924060929 changed the title Branch 3.0: [opt](nereids) optimize normalize window (#54947) Branch-3.0: [opt](nereids) optimize normalize window (#54947) Aug 20, 2025
@924060929 924060929 changed the title Branch-3.0: [opt](nereids) optimize normalize window (#54947) branch-3.0: [opt](nereids) optimize normalize window (#54947) Aug 20, 2025
@924060929
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17622	6834	6740	6740
q2	2052	212	176	176
q3	10486	1141	1207	1141
q4	10211	760	775	760
q5	7746	2879	2792	2792
q6	210	130	132	130
q7	981	632	629	629
q8	9421	2010	2028	2010
q9	8273	6414	6425	6414
q10	7056	2242	2295	2242
q11	474	265	270	265
q12	493	215	221	215
q13	17811	3015	2989	2989
q14	237	208	210	208
q15	525	457	460	457
q16	499	377	381	377
q17	971	593	559	559
q18	7099	6646	6752	6646
q19	1399	1141	1012	1012
q20	487	208	207	207
q21	3995	3118	3130	3118
q22	1133	993	1020	993
Total cold run time: 109181 ms
Total hot run time: 40080 ms

----- Round 2, with runtime_filter_mode=off -----
q1	6717	6613	6611	6611
q2	337	241	235	235
q3	3062	2898	2962	2898
q4	2070	1831	1793	1793
q5	5688	5790	5785	5785
q6	213	134	130	130
q7	2281	1857	1816	1816
q8	3388	3596	3450	3450
q9	9016	8964	8893	8893
q10	3550	3561	3531	3531
q11	585	528	503	503
q12	814	616	648	616
q13	3878	3208	3141	3141
q14	300	272	277	272
q15	559	478	470	470
q16	497	449	448	448
q17	1858	1632	1621	1621
q18	8269	7687	7686	7686
q19	1664	1611	1653	1611
q20	2148	1895	1847	1847
q21	5364	5141	5058	5058
q22	1154	1040	1037	1037
Total cold run time: 63412 ms
Total hot run time: 59452 ms

@doris-robot
Copy link

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

query1	931	408	406	406
query2	6240	1931	1838	1838
query3	8690	219	204	204
query4	33517	23439	24027	23439
query5	4059	482	445	445
query6	293	190	198	190
query7	4199	314	315	314
query8	284	233	228	228
query9	9586	2588	2585	2585
query10	476	272	287	272
query11	18246	15183	15250	15183
query12	164	105	102	102
query13	1554	425	427	425
query14	8905	8054	7289	7289
query15	253	173	181	173
query16	8147	538	485	485
query17	1650	610	585	585
query18	2230	339	338	338
query19	383	171	166	166
query20	126	120	122	120
query21	205	110	114	110
query22	4782	4634	4503	4503
query23	35381	34015	34526	34015
query24	11773	2975	2900	2900
query25	699	428	428	428
query26	1818	182	173	173
query27	2669	358	366	358
query28	7733	2146	2130	2130
query29	1064	454	465	454
query30	264	180	157	157
query31	1045	847	839	839
query32	94	64	61	61
query33	788	315	302	302
query34	922	545	509	509
query35	946	741	729	729
query36	1137	976	948	948
query37	185	72	76	72
query38	4097	3992	3936	3936
query39	1562	1488	1486	1486
query40	255	114	109	109
query41	52	48	52	48
query42	116	101	103	101
query43	532	481	487	481
query44	1228	829	816	816
query45	199	180	164	164
query46	1173	755	747	747
query47	2041	1882	1905	1882
query48	487	401	375	375
query49	1156	400	397	397
query50	835	448	434	434
query51	7530	7410	7247	7247
query52	101	93	97	93
query53	270	189	191	189
query54	1299	480	493	480
query55	83	80	78	78
query56	251	267	283	267
query57	1331	1223	1204	1204
query58	232	215	218	215
query59	3186	2978	2960	2960
query60	290	259	265	259
query61	126	157	122	122
query62	842	696	674	674
query63	220	195	186	186
query64	4942	658	622	622
query65	3304	3243	3258	3243
query66	1407	296	325	296
query67	15835	15546	15612	15546
query68	4873	592	586	586
query69	440	275	271	271
query70	1198	1077	1102	1077
query71	342	258	270	258
query72	6147	4045	4042	4042
query73	757	348	348	348
query74	10859	9019	9346	9019
query75	3394	2663	2670	2663
query76	3066	1056	1046	1046
query77	461	272	275	272
query78	10503	9645	9598	9598
query79	1537	610	603	603
query80	894	454	444	444
query81	545	222	219	219
query82	872	94	89	89
query83	243	148	154	148
query84	229	80	77	77
query85	1657	316	289	289
query86	476	307	296	296
query87	4378	4240	4329	4240
query88	4307	2374	2540	2374
query89	414	294	291	291
query90	2171	197	187	187
query91	181	150	151	150
query92	63	54	52	52
query93	2072	565	568	565
query94	1053	297	316	297
query95	361	264	262	262
query96	620	295	283	283
query97	3299	3160	3106	3106
query98	231	196	203	196
query99	1510	1285	1331	1285
Total cold run time: 305573 ms
Total hot run time: 192765 ms

@doris-robot
Copy link

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

query1	0.03	0.03	0.03
query2	0.07	0.03	0.03
query3	0.23	0.07	0.06
query4	1.63	0.11	0.11
query5	0.52	0.52	0.52
query6	1.14	0.73	0.72
query7	0.02	0.02	0.01
query8	0.04	0.04	0.03
query9	0.60	0.50	0.50
query10	0.56	0.55	0.55
query11	0.14	0.10	0.10
query12	0.14	0.11	0.11
query13	0.61	0.60	0.60
query14	0.76	0.80	0.79
query15	0.85	0.84	0.84
query16	0.40	0.38	0.39
query17	1.04	1.05	1.12
query18	0.24	0.22	0.22
query19	1.93	1.86	1.86
query20	0.02	0.02	0.01
query21	15.37	0.58	0.57
query22	2.28	2.08	2.53
query23	16.89	1.01	0.73
query24	3.34	0.76	1.05
query25	0.18	0.15	0.05
query26	0.56	0.13	0.14
query27	0.06	0.05	0.06
query28	10.45	0.51	0.49
query29	12.56	3.24	3.22
query30	0.25	0.05	0.06
query31	2.86	0.38	0.38
query32	3.25	0.46	0.46
query33	2.95	3.05	3.02
query34	17.23	4.54	4.57
query35	4.57	4.51	4.58
query36	0.68	0.48	0.50
query37	0.09	0.06	0.06
query38	0.05	0.04	0.03
query39	0.04	0.02	0.02
query40	0.17	0.12	0.12
query41	0.07	0.02	0.03
query42	0.03	0.02	0.02
query43	0.03	0.02	0.03
Total cold run time: 104.93 s
Total hot run time: 30.33 s

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

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

@924060929
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17591	7340	6583	6583
q2	2043	192	170	170
q3	10624	1148	1159	1148
q4	10446	727	765	727
q5	7761	2892	2801	2801
q6	208	133	131	131
q7	982	601	594	594
q8	9354	1966	2032	1966
q9	6693	6424	6420	6420
q10	6980	2289	2272	2272
q11	473	262	260	260
q12	395	217	211	211
q13	17793	2975	2990	2975
q14	234	207	208	207
q15	530	460	461	460
q16	478	374	376	374
q17	977	545	586	545
q18	7336	6596	6690	6596
q19	1398	1055	1015	1015
q20	460	201	203	201
q21	3871	3193	2997	2997
q22	1109	988	995	988
Total cold run time: 107736 ms
Total hot run time: 39641 ms

----- Round 2, with runtime_filter_mode=off -----
q1	6599	6551	6576	6551
q2	337	231	230	230
q3	2936	2971	2905	2905
q4	2048	1876	1861	1861
q5	5743	5727	5703	5703
q6	209	129	131	129
q7	2208	1827	1824	1824
q8	3374	3618	3552	3552
q9	8807	8886	8841	8841
q10	3558	3507	3538	3507
q11	587	510	490	490
q12	792	593	632	593
q13	7989	3140	3197	3140
q14	308	280	270	270
q15	517	457	464	457
q16	489	441	443	441
q17	1841	1631	1598	1598
q18	8423	7746	7598	7598
q19	1654	1632	1604	1604
q20	2136	1867	1894	1867
q21	5228	5113	5115	5113
q22	1142	1049	1058	1049
Total cold run time: 66925 ms
Total hot run time: 59323 ms

@doris-robot
Copy link

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

query1	937	419	419	419
query2	6252	1898	1900	1898
query3	8689	199	200	199
query4	33237	23507	24121	23507
query5	3971	471	450	450
query6	302	204	204	204
query7	4216	340	322	322
query8	295	230	227	227
query9	9459	2606	2603	2603
query10	493	257	256	256
query11	17823	15206	15195	15195
query12	149	105	116	105
query13	1544	422	433	422
query14	8605	6725	7265	6725
query15	257	173	183	173
query16	8019	505	481	481
query17	1636	649	584	584
query18	2166	313	340	313
query19	266	174	158	158
query20	125	114	115	114
query21	210	106	108	106
query22	4755	4455	4833	4455
query23	34975	33883	34176	33883
query24	11808	2930	2930	2930
query25	696	428	443	428
query26	1811	170	170	170
query27	3069	352	356	352
query28	7539	2226	2164	2164
query29	1038	434	428	428
query30	261	160	159	159
query31	1046	817	828	817
query32	104	56	60	56
query33	786	300	300	300
query34	1328	521	517	517
query35	879	712	716	712
query36	1102	943	971	943
query37	286	69	70	69
query38	4132	3952	3980	3952
query39	1529	1665	1469	1469
query40	258	101	102	101
query41	50	50	47	47
query42	114	102	100	100
query43	516	472	475	472
query44	1247	831	816	816
query45	190	170	173	170
query46	1165	713	748	713
query47	2044	1873	1946	1873
query48	483	382	390	382
query49	1186	400	408	400
query50	826	428	430	428
query51	7466	7148	7232	7148
query52	100	90	91	90
query53	257	187	189	187
query54	1347	468	471	468
query55	88	83	77	77
query56	275	252	257	252
query57	1360	1261	1200	1200
query58	230	204	219	204
query59	3209	3094	3083	3083
query60	284	274	249	249
query61	118	107	107	107
query62	929	694	673	673
query63	216	184	186	184
query64	4895	652	627	627
query65	3270	3258	3190	3190
query66	1378	292	292	292
query67	16153	15576	15582	15576
query68	5502	603	574	574
query69	417	290	266	266
query70	1159	1112	1126	1112
query71	346	283	250	250
query72	6178	4067	4019	4019
query73	744	346	345	345
query74	9758	9053	9255	9053
query75	3376	2602	2628	2602
query76	3350	1038	1135	1038
query77	380	295	270	270
query78	10425	9650	9576	9576
query79	2577	610	619	610
query80	1081	423	426	423
query81	548	227	219	219
query82	614	87	84	84
query83	228	146	145	145
query84	233	78	84	78
query85	1463	315	307	307
query86	454	302	274	274
query87	4357	4233	4230	4230
query88	4167	2403	2358	2358
query89	406	291	295	291
query90	2218	187	191	187
query91	192	152	150	150
query92	64	50	53	50
query93	2418	564	558	558
query94	1080	313	303	303
query95	357	262	253	253
query96	604	280	279	279
query97	3364	3165	3133	3133
query98	218	198	204	198
query99	1503	1293	1310	1293
Total cold run time: 305230 ms
Total hot run time: 191902 ms

@doris-robot
Copy link

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

query1	0.03	0.03	0.03
query2	0.06	0.03	0.03
query3	0.23	0.07	0.06
query4	1.63	0.10	0.10
query5	0.53	0.52	0.50
query6	1.13	0.73	0.72
query7	0.02	0.02	0.01
query8	0.04	0.03	0.04
query9	0.55	0.52	0.49
query10	0.54	0.55	0.55
query11	0.14	0.10	0.10
query12	0.13	0.11	0.11
query13	0.61	0.59	0.61
query14	0.77	0.81	0.79
query15	0.85	0.84	0.82
query16	0.39	0.38	0.38
query17	1.06	1.08	1.06
query18	0.23	0.23	0.22
query19	1.96	1.88	1.90
query20	0.02	0.03	0.01
query21	15.39	0.57	0.59
query22	2.14	2.25	1.60
query23	16.88	0.90	0.92
query24	2.57	1.06	1.93
query25	0.26	0.05	0.06
query26	0.45	0.13	0.14
query27	0.05	0.05	0.04
query28	10.05	0.49	0.50
query29	12.55	3.22	3.23
query30	0.25	0.06	0.06
query31	2.86	0.38	0.38
query32	3.25	0.45	0.45
query33	3.01	3.01	3.06
query34	17.16	4.50	4.46
query35	4.61	4.57	4.57
query36	0.65	0.49	0.47
query37	0.08	0.06	0.06
query38	0.05	0.04	0.03
query39	0.03	0.02	0.03
query40	0.16	0.13	0.13
query41	0.08	0.02	0.02
query42	0.04	0.02	0.02
query43	0.03	0.02	0.02
Total cold run time: 103.52 s
Total hot run time: 30.24 s

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

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

Copy link
Contributor

@dataroaring dataroaring left a comment

Choose a reason for hiding this comment

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

LGTM

@dataroaring dataroaring merged commit 10ddc8b into apache:branch-3.0 Sep 3, 2025
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants