Skip to content

Conversation

@924060929
Copy link
Contributor

cherry pick #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 morrySnow as a code owner August 20, 2025 05:33
@Thearas
Copy link
Contributor

Thearas commented Aug 20, 2025

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
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17604	5497	5534	5497
q2	2028	413	278	278
q3	12565	1929	744	744
q4	10855	876	455	455
q5	9702	2392	2148	2148
q6	211	167	135	135
q7	894	756	614	614
q8	9350	1421	1098	1098
q9	5290	4967	4878	4878
q10	6796	2283	1836	1836
q11	473	285	267	267
q12	338	348	213	213
q13	17788	3617	3001	3001
q14	224	235	218	218
q15	532	481	478	478
q16	423	416	366	366
q17	605	860	362	362
q18	6711	6543	6224	6224
q19	1198	958	546	546
q20	321	342	209	209
q21	2779	2136	1912	1912
q22	1046	1019	1002	1002
Total cold run time: 107733 ms
Total hot run time: 32481 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5620	5487	5520	5487
q2	235	328	234	234
q3	2279	2629	2360	2360
q4	1359	1797	1395	1395
q5	4427	5038	4955	4955
q6	171	157	128	128
q7	2057	1939	1826	1826
q8	2639	2785	2722	2722
q9	7254	7234	7230	7230
q10	3032	3215	2803	2803
q11	584	534	487	487
q12	698	780	626	626
q13	3359	3727	3158	3158
q14	274	305	278	278
q15	526	462	480	462
q16	434	502	429	429
q17	1209	1747	1250	1250
q18	7570	7396	7303	7303
q19	807	1153	1082	1082
q20	2039	2054	1899	1899
q21	5472	4987	4577	4577
q22	1079	1078	1035	1035
Total cold run time: 53124 ms
Total hot run time: 51726 ms

@doris-robot
Copy link

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

query1	940	390	385	385
query2	6316	1987	1986	1986
query3	8701	205	204	204
query4	33697	23626	23381	23381
query5	3730	609	473	473
query6	308	196	175	175
query7	4207	485	314	314
query8	298	236	234	234
query9	9056	2594	2568	2568
query10	472	318	268	268
query11	18254	15659	15229	15229
query12	160	114	106	106
query13	1558	564	407	407
query14	10498	6635	7001	6635
query15	249	188	182	182
query16	8056	664	516	516
query17	1566	778	604	604
query18	2160	419	352	352
query19	222	207	179	179
query20	135	129	119	119
query21	215	128	107	107
query22	4625	4552	4434	4434
query23	35017	33861	34208	33861
query24	7343	2709	2698	2698
query25	551	511	430	430
query26	778	285	174	174
query27	1947	491	355	355
query28	5228	2207	2188	2188
query29	740	612	476	476
query30	245	190	165	165
query31	998	925	821	821
query32	89	61	59	59
query33	553	364	313	313
query34	763	863	540	540
query35	766	822	761	761
query36	1029	1039	944	944
query37	104	93	64	64
query38	4024	4040	3972	3972
query39	1677	1535	1465	1465
query40	228	128	113	113
query41	52	50	49	49
query42	128	108	104	104
query43	522	550	510	510
query44	1337	805	845	805
query45	196	181	181	181
query46	901	1089	677	677
query47	1972	1992	1945	1945
query48	419	426	354	354
query49	730	488	413	413
query50	686	705	428	428
query51	7390	7312	7281	7281
query52	107	103	93	93
query53	225	253	186	186
query54	545	549	465	465
query55	81	79	84	79
query56	290	276	268	268
query57	1278	1285	1221	1221
query58	243	221	225	221
query59	3143	3206	3171	3171
query60	291	280	267	267
query61	113	110	109	109
query62	791	743	700	700
query63	250	199	202	199
query64	3772	1031	640	640
query65	3337	3292	3281	3281
query66	834	402	300	300
query67	16245	15870	15624	15624
query68	7692	839	545	545
query69	493	328	275	275
query70	1199	1153	1076	1076
query71	430	293	257	257
query72	5224	3693	3826	3693
query73	661	737	346	346
query74	10202	9221	8961	8961
query75	3674	3140	2664	2664
query76	3529	1191	785	785
query77	771	373	278	278
query78	10306	10467	9657	9657
query79	3374	925	584	584
query80	654	518	434	434
query81	500	258	227	227
query82	593	125	89	89
query83	163	158	147	147
query84	232	107	77	77
query85	793	385	300	300
query86	389	302	302	302
query87	4385	4270	4237	4237
query88	5151	2384	2369	2369
query89	410	337	293	293
query90	1712	188	192	188
query91	138	141	104	104
query92	60	57	51	51
query93	2046	911	538	538
query94	633	418	309	309
query95	336	281	268	268
query96	488	608	287	287
query97	3187	3326	3147	3147
query98	221	218	203	203
query99	1574	1393	1334	1334
Total cold run time: 294601 ms
Total hot run time: 191853 ms

@doris-robot
Copy link

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

query1	0.03	0.03	0.03
query2	0.06	0.03	0.03
query3	0.24	0.06	0.07
query4	1.62	0.11	0.10
query5	0.52	0.52	0.51
query6	1.13	0.72	0.74
query7	0.02	0.01	0.01
query8	0.04	0.03	0.04
query9	0.58	0.51	0.49
query10	0.55	0.56	0.55
query11	0.14	0.10	0.10
query12	0.17	0.10	0.11
query13	0.62	0.60	0.60
query14	0.76	0.79	0.80
query15	0.86	0.84	0.82
query16	0.38	0.40	0.41
query17	1.08	1.03	1.02
query18	0.24	0.23	0.23
query19	1.98	1.82	1.91
query20	0.02	0.01	0.01
query21	15.40	0.89	0.57
query22	0.75	0.69	0.63
query23	15.25	1.43	0.63
query24	3.59	1.04	0.29
query25	0.16	0.07	0.14
query26	0.35	0.15	0.14
query27	0.05	0.05	0.04
query28	12.60	1.06	0.42
query29	12.62	4.00	3.29
query30	0.26	0.09	0.06
query31	2.83	0.59	0.38
query32	3.23	0.53	0.47
query33	3.03	3.00	3.06
query34	16.75	5.17	4.56
query35	4.54	4.56	4.55
query36	0.66	0.50	0.48
query37	0.09	0.07	0.06
query38	0.05	0.04	0.04
query39	0.04	0.03	0.02
query40	0.17	0.13	0.12
query41	0.08	0.03	0.02
query42	0.03	0.02	0.02
query43	0.03	0.03	0.03
Total cold run time: 103.6 s
Total hot run time: 28.31 s

@morrySnow morrySnow changed the title branch-3.1: [opt](nereids) optimize normalize window (#54947) branch-3.1: [opt](nereids) optimize normalize window #54947 Sep 4, 2025
@morrySnow morrySnow merged commit 883d84f into apache:branch-3.1 Sep 4, 2025
24 checks passed
@morrySnow morrySnow mentioned this pull request Sep 22, 2025
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