Skip to content

[fix](be) Fix nth_value for upper bounded windows#64864

Merged
morrySnow merged 2 commits into
apache:masterfrom
morrySnow:fix-window
Jun 26, 2026
Merged

[fix](be) Fix nth_value for upper bounded windows#64864
morrySnow merged 2 commits into
apache:masterfrom
morrySnow:fix-window

Conversation

@morrySnow

@morrySnow morrySnow commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Related PR: #50559

Problem Summary: nth_value over an upper-bounded/lower-unbounded window frame such as ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING is normalized by reversing the order and frame, then evaluating nth_value with a negative offset over a cumulative frame. The BE nth_value window state replaced the tracked frame row count on each range update, so later rows in the cumulative frame could address the wrong row or return NULL. The fix keeps the cumulative frame row count across range updates, and FE preserves literal offset typing when negating bigint nth_value arguments. This adds BE unit coverage for the reversed cumulative execution path and a regression case comparing nth_value to lead for the original SQL frame.

Release note

Fix nth_value results for ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING window frames.

Check List (For Author)

  • Test: Regression test; style check
    • Regression test: ./run-regression-test.sh --run -d query_p0/sql_functions/window_functions -s test_nthvalue_function -forceGenOut
    • Style check: build-support/check-format.sh
    • Unit Test: BE UT added but not completed locally because the ASAN UT build was too slow in this environment
  • Behavior changed: Yes. Fixes incorrect nth_value results for upper-bounded/lower-unbounded window frames.
  • Does this need documentation: No

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: Nereids reverses order keys and window frames for frames ending with UNBOUNDED FOLLOWING so BE can execute an equivalent supported frame shape. nth_value depends on the position within the frame, so reversing the order without adjusting its offset changes the result. This change lets BE interpret negative nth_value offsets as counting from the end of the frame, and rewrites nth_value's offset to 0 - offset when Nereids applies the reverse-window transformation.

### Release note

None

### Check List (For Author)

- Test: Manual test
    - Ran git diff --check for the modified BE and FE files. Did not compile per user request.
- Behavior changed: Yes. nth_value keeps equivalent semantics when the window frame is reversed for execution.
- Does this need documentation: No
@hello-stephen

Copy link
Copy Markdown
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?

@morrySnow

Copy link
Copy Markdown
Contributor Author

run buildall

1 similar comment
@morrySnow

Copy link
Copy Markdown
Contributor Author

run buildall

@morrySnow

Copy link
Copy Markdown
Contributor Author

/review

@morrySnow morrySnow marked this pull request as ready for review June 25, 2026 18:03

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review result: request changes.

Critical checkpoints:

  • Goal/test proof: the PR targets nth_value correctness for reversed upper-bounded ROWS frames. The production FE/BE direction looks coherent, and the regression case checks the SQL behavior, but the new BE unit test does not prove the intended executor path because it feeds the aggregate state with a different range protocol.
  • Scope/focus: the implementation is narrowly scoped to nth_value offset reversal and BE negative-offset interpretation.
  • Concurrency/lifecycle/config/compatibility: no new concurrency, lifecycle-managed resource, dynamic config, storage format, or FE-BE protocol compatibility issue found in the changed production paths.
  • Parallel paths: Nereids reversal, physical window translation, BE argument materialization, and ROWS execution were checked. No additional optimizer/rewrite issue found.
  • Tests/style: regression output is deterministic and matches the SQL expectation. The accepted issue is in the new BE UT expectations/call sequence. Targeted patch sweep found no extra style candidate in the five live PR files.

User focus: no additional user-provided review focus.

Subagent conclusions: optimizer-rewrite reported no new candidates in the convergence round. tests-session-config reported TSC-001 as a duplicate of MAIN-001, and no new candidate in the convergence round. The final accepted inline comment set contains MAIN-001 only.

&could_use_previous_result);
function->insert_result_into(place, *result_column);

function->add_range_single_place(0, 3, 0, 2, place, columns, arena, &use_null_result,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The direct test does not mirror the executor protocol for this window shape. After FE reverses ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING, _get_next_for_unbounded_rows() feeds nth_value only the newly added range (current_row_end - 1, current_row_end) on each row. This test instead calls [0,1), then [0,2), then [0,3). With the implementation above, _frame_total_rows becomes 1, then 3, then 6, so offset -2 reads position 1 ("B") for the second result and later goes past the three-row input, rather than producing the expected "C"/"B". Please change the test to feed the same delta ranges as the analytic executor (for example [0,1), [1,2), [2,3)) or reset state between full-frame evaluations; otherwise the added BE UT will fail when it is run.

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17689	4093	4022	4022
q2	2030	303	195	195
q3	10337	1396	842	842
q4	4682	466	339	339
q5	7534	869	563	563
q6	183	169	139	139
q7	752	863	617	617
q8	9526	1549	1592	1549
q9	5930	4456	4480	4456
q10	6829	1785	1512	1512
q11	450	271	241	241
q12	647	423	306	306
q13	18187	3444	2699	2699
q14	284	255	246	246
q15	q16	786	793	705	705
q17	953	990	984	984
q18	6868	5859	5557	5557
q19	1330	1240	1094	1094
q20	488	401	284	284
q21	5963	2770	2336	2336
q22	431	374	306	306
Total cold run time: 101879 ms
Total hot run time: 28992 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4338	4277	4296	4277
q2	310	348	213	213
q3	4656	4935	4460	4460
q4	2062	2164	1362	1362
q5	4400	4288	4330	4288
q6	226	173	130	130
q7	1747	1715	1900	1715
q8	2492	2154	2096	2096
q9	8223	8163	8116	8116
q10	4811	4762	4329	4329
q11	559	452	401	401
q12	740	744	620	620
q13	3274	3556	2966	2966
q14	314	331	267	267
q15	q16	717	731	649	649
q17	1339	1293	1317	1293
q18	8186	7341	7023	7023
q19	1178	1075	1083	1075
q20	2309	2249	1973	1973
q21	5252	4574	4434	4434
q22	512	456	406	406
Total cold run time: 57645 ms
Total hot run time: 52093 ms

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17607	3982	3941	3941
q2	1993	299	201	201
q3	10308	1385	799	799
q4	4678	469	337	337
q5	7522	836	573	573
q6	170	165	136	136
q7	756	852	623	623
q8	9624	1473	1522	1473
q9	5998	4494	4500	4494
q10	6812	1799	1539	1539
q11	450	275	251	251
q12	672	435	288	288
q13	18120	3291	2661	2661
q14	263	255	238	238
q15	q16	778	785	705	705
q17	1005	978	987	978
q18	7013	5683	5605	5605
q19	1774	1286	1113	1113
q20	493	414	258	258
q21	5717	2690	2348	2348
q22	412	356	297	297
Total cold run time: 102165 ms
Total hot run time: 28858 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4338	4208	4225	4208
q2	306	337	225	225
q3	4581	4942	4393	4393
q4	2009	2141	1364	1364
q5	4366	4264	4259	4259
q6	224	170	126	126
q7	1708	1620	1707	1620
q8	2497	2153	2116	2116
q9	7954	8079	8068	8068
q10	4786	4722	4269	4269
q11	555	403	364	364
q12	724	743	530	530
q13	3413	3550	2947	2947
q14	336	305	287	287
q15	q16	732	737	665	665
q17	1346	1312	1307	1307
q18	8067	7326	6919	6919
q19	1092	1039	1090	1039
q20	2218	2204	1967	1967
q21	5187	4522	4372	4372
q22	518	451	407	407
Total cold run time: 56957 ms
Total hot run time: 51452 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 171739 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 64760dc99236023406c146157f3d44fd593791de, data reload: false

query5	4326	627	485	485
query6	441	186	170	170
query7	4946	509	307	307
query8	328	178	168	168
query9	9338	4280	4213	4213
query10	440	319	307	307
query11	5929	2354	2095	2095
query12	156	102	100	100
query13	1265	579	413	413
query14	6255	5279	4920	4920
query14_1	4307	4257	4295	4257
query15	201	199	173	173
query16	993	448	423	423
query17	914	715	565	565
query18	2415	464	344	344
query19	191	179	140	140
query20	116	106	104	104
query21	219	137	113	113
query22	13637	13733	13420	13420
query23	17231	16425	16187	16187
query23_1	16171	16316	16227	16227
query24	7431	1779	1321	1321
query24_1	1349	1313	1302	1302
query25	572	460	390	390
query26	1318	324	179	179
query27	2648	564	331	331
query28	4476	2031	2028	2028
query29	1074	620	505	505
query30	310	243	197	197
query31	1103	1090	949	949
query32	110	64	70	64
query33	539	326	267	267
query34	1181	1110	659	659
query35	780	789	681	681
query36	1415	1387	1219	1219
query37	155	109	96	96
query38	1879	1723	1693	1693
query39	935	927	907	907
query39_1	879	865	914	865
query40	215	123	106	106
query41	76	69	72	69
query42	90	90	89	89
query43	325	324	284	284
query44	1433	793	785	785
query45	198	212	183	183
query46	1081	1182	723	723
query47	2364	2404	2249	2249
query48	421	424	312	312
query49	587	435	323	323
query50	1071	367	270	270
query51	4452	4419	4354	4354
query52	83	83	72	72
query53	246	270	191	191
query54	271	232	212	212
query55	78	74	71	71
query56	254	229	223	223
query57	1424	1418	1320	1320
query58	249	220	220	220
query59	1576	1667	1438	1438
query60	288	261	246	246
query61	175	208	147	147
query62	696	648	576	576
query63	228	190	194	190
query64	2527	763	616	616
query65	4828	4766	4750	4750
query66	1790	458	332	332
query67	28179	28845	28668	28668
query68	3141	1516	937	937
query69	409	295	262	262
query70	1075	983	955	955
query71	283	224	209	209
query72	2867	2681	2300	2300
query73	843	740	424	424
query74	5159	4970	4795	4795
query75	2599	2534	2209	2209
query76	2333	1190	782	782
query77	350	381	294	294
query78	12461	12430	11829	11829
query79	1416	1184	776	776
query80	866	457	367	367
query81	490	275	233	233
query82	570	159	118	118
query83	322	270	243	243
query84	306	146	113	113
query85	878	518	412	412
query86	412	326	304	304
query87	1868	1824	1781	1781
query88	3684	2791	2780	2780
query89	429	382	337	337
query90	1948	184	186	184
query91	203	162	132	132
query92	61	62	56	56
query93	1561	1463	861	861
query94	617	363	309	309
query95	675	382	438	382
query96	1123	832	376	376
query97	2716	2689	2567	2567
query98	228	206	200	200
query99	1176	1154	1045	1045
Total cold run time: 256384 ms
Total hot run time: 171739 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 25.24 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 64760dc99236023406c146157f3d44fd593791de, data reload: false

query1	0.00	0.00	0.00
query2	0.10	0.06	0.05
query3	0.26	0.14	0.14
query4	1.61	0.13	0.13
query5	0.25	0.22	0.23
query6	1.26	1.08	1.08
query7	0.04	0.01	0.01
query8	0.06	0.04	0.04
query9	0.38	0.32	0.31
query10	0.55	0.55	0.58
query11	0.20	0.17	0.14
query12	0.18	0.14	0.15
query13	0.47	0.48	0.48
query14	1.01	1.00	1.00
query15	0.63	0.59	0.59
query16	0.32	0.34	0.31
query17	1.16	1.08	1.07
query18	0.22	0.22	0.22
query19	2.06	1.94	1.94
query20	0.02	0.02	0.01
query21	15.42	0.18	0.14
query22	4.95	0.06	0.05
query23	16.15	0.31	0.12
query24	3.02	0.40	0.32
query25	0.11	0.06	0.04
query26	0.73	0.21	0.14
query27	0.03	0.03	0.04
query28	3.50	0.88	0.53
query29	12.50	4.25	3.46
query30	0.27	0.15	0.15
query31	2.76	0.61	0.31
query32	3.22	0.59	0.51
query33	3.22	3.21	3.19
query34	15.63	4.15	3.54
query35	3.56	3.51	3.53
query36	0.54	0.44	0.42
query37	0.08	0.06	0.07
query38	0.04	0.04	0.03
query39	0.04	0.02	0.02
query40	0.18	0.15	0.16
query41	0.08	0.03	0.03
query42	0.04	0.03	0.04
query43	0.04	0.03	0.04
Total cold run time: 96.89 s
Total hot run time: 25.24 s

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 170958 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 64760dc99236023406c146157f3d44fd593791de, data reload: false

query5	4337	613	481	481
query6	415	183	174	174
query7	4809	529	296	296
query8	343	180	162	162
query9	8768	4016	3963	3963
query10	453	296	254	254
query11	5938	2305	2110	2110
query12	161	100	99	99
query13	1307	595	433	433
query14	6273	5274	4947	4947
query14_1	4294	4282	4242	4242
query15	215	202	178	178
query16	999	456	453	453
query17	1134	728	582	582
query18	2707	488	354	354
query19	210	191	154	154
query20	112	110	106	106
query21	224	136	114	114
query22	13722	13584	13363	13363
query23	17294	16414	16117	16117
query23_1	16160	16248	16210	16210
query24	7466	1737	1298	1298
query24_1	1330	1317	1308	1308
query25	559	461	391	391
query26	1286	327	169	169
query27	2687	573	355	355
query28	4970	2035	2085	2035
query29	1064	601	462	462
query30	302	225	199	199
query31	1102	1081	941	941
query32	101	58	68	58
query33	497	310	243	243
query34	1175	1143	649	649
query35	770	805	666	666
query36	1382	1356	1270	1270
query37	150	99	93	93
query38	1873	1698	1658	1658
query39	923	921	884	884
query39_1	868	879	899	879
query40	221	120	98	98
query41	65	63	62	62
query42	90	91	85	85
query43	313	318	280	280
query44	1465	785	794	785
query45	192	185	178	178
query46	1054	1212	713	713
query47	2404	2359	2301	2301
query48	393	414	298	298
query49	603	410	307	307
query50	953	354	263	263
query51	4409	4422	4285	4285
query52	80	80	69	69
query53	246	257	191	191
query54	259	223	195	195
query55	73	71	65	65
query56	235	221	236	221
query57	1441	1433	1320	1320
query58	243	204	202	202
query59	1553	1605	1451	1451
query60	279	242	229	229
query61	149	146	165	146
query62	699	644	584	584
query63	223	184	192	184
query64	2463	771	605	605
query65	4883	4776	4765	4765
query66	1762	450	342	342
query67	28711	28733	28584	28584
query68	3355	1512	1010	1010
query69	411	299	268	268
query70	1100	981	966	966
query71	288	235	216	216
query72	2868	2615	2337	2337
query73	846	780	454	454
query74	5091	4915	4733	4733
query75	2569	2501	2165	2165
query76	2358	1162	783	783
query77	353	375	279	279
query78	12445	12332	11815	11815
query79	1382	1227	764	764
query80	1301	470	384	384
query81	524	276	246	246
query82	609	156	118	118
query83	347	269	241	241
query84	266	141	109	109
query85	910	512	405	405
query86	422	299	292	292
query87	1847	1817	1776	1776
query88	3733	2783	2768	2768
query89	444	381	324	324
query90	1898	180	182	180
query91	170	157	132	132
query92	62	57	57	57
query93	1607	1485	886	886
query94	718	347	312	312
query95	686	382	360	360
query96	1086	835	342	342
query97	2739	2682	2566	2566
query98	214	202	202	202
query99	1165	1146	1003	1003
Total cold run time: 258115 ms
Total hot run time: 170958 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 25.09 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 64760dc99236023406c146157f3d44fd593791de, data reload: false

query1	0.00	0.00	0.00
query2	0.09	0.04	0.05
query3	0.25	0.13	0.13
query4	1.61	0.13	0.13
query5	0.23	0.22	0.21
query6	1.29	1.08	1.05
query7	0.04	0.01	0.01
query8	0.06	0.04	0.04
query9	0.37	0.33	0.31
query10	0.53	0.55	0.54
query11	0.19	0.14	0.13
query12	0.18	0.15	0.14
query13	0.46	0.46	0.47
query14	1.02	1.00	0.98
query15	0.61	0.59	0.61
query16	0.30	0.31	0.31
query17	1.12	1.09	1.05
query18	0.22	0.20	0.21
query19	2.04	1.96	1.97
query20	0.02	0.01	0.01
query21	15.43	0.19	0.13
query22	4.91	0.06	0.05
query23	16.11	0.30	0.11
query24	2.86	0.42	0.32
query25	0.12	0.05	0.04
query26	0.73	0.20	0.14
query27	0.06	0.03	0.03
query28	3.49	0.95	0.52
query29	12.47	4.35	3.46
query30	0.28	0.15	0.15
query31	2.77	0.58	0.30
query32	3.21	0.60	0.49
query33	3.17	3.17	3.21
query34	15.58	4.18	3.56
query35	3.51	3.52	3.57
query36	0.54	0.44	0.45
query37	0.09	0.07	0.06
query38	0.05	0.04	0.03
query39	0.04	0.03	0.03
query40	0.18	0.16	0.15
query41	0.09	0.04	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.04
Total cold run time: 96.4 s
Total hot run time: 25.09 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 0.00% (0/8) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 75.00% (6/8) 🎉
Increment coverage report
Complete coverage report

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: nth_value over an upper-bounded/lower-unbounded window frame such as ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING is normalized by reversing the order and frame, then evaluating nth_value with a negative offset over a cumulative frame. The BE nth_value window state replaced the tracked frame row count on each range update, so later rows in the cumulative frame could address the wrong row or return NULL. The fix keeps the cumulative frame row count across range updates, and FE preserves literal offset typing when negating bigint nth_value arguments. This adds BE unit coverage for the reversed cumulative execution path and a regression case comparing nth_value to lead for the original SQL frame.

### Release note

Fix nth_value results for ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING window frames.

### Check List (For Author)

- Test: Regression test; style check

    - Regression test: ./run-regression-test.sh --run -d query_p0/sql_functions/window_functions -s test_nthvalue_function -forceGenOut

    - Style check: build-support/check-format.sh

    - Unit Test: BE UT added but not completed locally because the ASAN UT build was too slow in this environment

- Behavior changed: Yes. Fixes incorrect nth_value results for upper-bounded/lower-unbounded window frames.

- Does this need documentation: No
@morrySnow

Copy link
Copy Markdown
Contributor Author

run buildall

@morrySnow

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review result: request changes.

Critical checkpoints:

  • Goal/test proof: the PR targets nth_value correctness for reversed upper-bounded ROWS frames. The CURRENT ROW AND UNBOUNDED FOLLOWING regression and updated BE UT now cover that executor protocol, but n FOLLOWING AND UNBOUNDED FOLLOWING remains incorrect.
  • Scope/focus: the production change is narrowly scoped to Nereids nth_value offset reversal and BE negative-offset interpretation.
  • Concurrency/lifecycle/config/compatibility: no new concurrency, lifecycle-managed resource, dynamic config, storage format, or FE-BE protocol compatibility issue found.
  • Parallel paths: I checked Nereids frame reversal, BE unbounded/sliding ROWS execution, and the current regression/UT paths. The remaining issue is in the parallel reversed frame shape whose right boundary becomes n PRECEDING.
  • Tests/style: git diff --check passed on the exact PR range. I did not run FE/BE/regression tests locally because this checkout is not worktree-initialized and thirdparty/installed is absent.

User focus: no additional user-provided review focus.

Subagent conclusions: optimizer-rewrite proposed OR-001, which was verified and merged into MAIN-001 as the accepted inline comment. tests-session-config reported no new candidates. In final convergence round 1, both optimizer-rewrite and tests-session-config replied NO_NEW_VALUABLE_FINDINGS for the same ledger/comment set after MAIN-001 was accepted.

Comment thread be/src/exprs/aggregate/aggregate_function_window.h
@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17939	4142	4097	4097
q2	2055	319	199	199
q3	10292	1432	858	858
q4	4686	464	336	336
q5	7561	1018	568	568
q6	187	171	137	137
q7	803	852	637	637
q8	9324	1545	1639	1545
q9	5599	4524	4515	4515
q10	6789	1848	1513	1513
q11	439	268	247	247
q12	633	425	292	292
q13	18071	3432	2740	2740
q14	264	263	242	242
q15	q16	792	775	715	715
q17	947	1024	966	966
q18	6843	5823	5672	5672
q19	1330	1230	1049	1049
q20	510	402	264	264
q21	6084	2636	2334	2334
q22	439	363	303	303
Total cold run time: 101587 ms
Total hot run time: 29229 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4487	4391	4376	4376
q2	329	348	228	228
q3	4638	4931	4419	4419
q4	2068	2126	1379	1379
q5	4487	4308	4311	4308
q6	231	181	130	130
q7	1725	1947	1807	1807
q8	2555	2167	2156	2156
q9	8347	8556	8133	8133
q10	4825	4800	4334	4334
q11	568	443	395	395
q12	771	782	533	533
q13	3406	3594	2979	2979
q14	301	297	283	283
q15	q16	725	723	645	645
q17	1339	1298	1345	1298
q18	8102	7297	7256	7256
q19	1182	1170	1167	1167
q20	2235	2201	1965	1965
q21	5265	4622	4519	4519
q22	514	455	401	401
Total cold run time: 58100 ms
Total hot run time: 52711 ms

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 100.00% (5/5) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 54.95% (21598/39307)
Line Coverage 38.43% (206529/537380)
Region Coverage 34.48% (162455/471200)
Branch Coverage 35.51% (71178/200464)

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 172327 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 a2163a62202d72e8d284b9268ce3749f8c3f0c3b, data reload: false

query5	4308	621	483	483
query6	444	196	185	185
query7	4826	601	306	306
query8	328	179	169	169
query9	8830	4080	4062	4062
query10	476	326	269	269
query11	5991	2356	2116	2116
query12	162	105	99	99
query13	1273	631	433	433
query14	6138	5362	5048	5048
query14_1	4375	4337	4349	4337
query15	211	202	187	187
query16	1028	465	398	398
query17	958	747	602	602
query18	2441	475	349	349
query19	213	193	157	157
query20	111	108	111	108
query21	221	144	117	117
query22	13629	13607	13514	13514
query23	17361	16618	16180	16180
query23_1	16280	16409	16309	16309
query24	7594	1840	1317	1317
query24_1	1325	1313	1322	1313
query25	588	463	393	393
query26	1309	344	176	176
query27	2661	586	344	344
query28	4534	2040	2043	2040
query29	1089	635	498	498
query30	312	234	200	200
query31	1137	1085	958	958
query32	114	63	62	62
query33	550	329	258	258
query34	1237	1172	642	642
query35	768	800	673	673
query36	1395	1391	1228	1228
query37	159	112	107	107
query38	1899	1724	1681	1681
query39	970	918	906	906
query39_1	892	868	886	868
query40	213	124	99	99
query41	63	62	65	62
query42	95	85	86	85
query43	336	337	296	296
query44	1467	791	793	791
query45	206	195	181	181
query46	1098	1217	760	760
query47	2341	2318	2196	2196
query48	405	404	294	294
query49	590	447	313	313
query50	984	354	262	262
query51	4380	4395	4353	4353
query52	83	82	72	72
query53	253	270	195	195
query54	263	238	206	206
query55	72	72	68	68
query56	232	221	204	204
query57	1413	1397	1309	1309
query58	270	214	212	212
query59	1651	1688	1491	1491
query60	283	242	225	225
query61	148	148	150	148
query62	713	651	581	581
query63	229	189	194	189
query64	2554	770	593	593
query65	4847	4804	4757	4757
query66	1790	470	329	329
query67	29163	28800	28718	28718
query68	3144	1580	981	981
query69	413	319	277	277
query70	1114	975	967	967
query71	287	238	218	218
query72	2916	2592	2298	2298
query73	851	763	424	424
query74	5138	4916	4774	4774
query75	2588	2538	2166	2166
query76	2326	1217	854	854
query77	360	380	290	290
query78	12568	12543	12018	12018
query79	1446	1185	751	751
query80	972	469	385	385
query81	498	281	239	239
query82	584	156	123	123
query83	350	283	257	257
query84	325	148	116	116
query85	938	520	418	418
query86	453	305	284	284
query87	1849	1853	1748	1748
query88	3741	2785	2777	2777
query89	443	379	346	346
query90	1766	187	181	181
query91	172	159	132	132
query92	60	58	56	56
query93	1550	1486	928	928
query94	642	358	318	318
query95	698	377	350	350
query96	1014	776	325	325
query97	2707	2693	2560	2560
query98	217	207	197	197
query99	1221	1164	1031	1031
Total cold run time: 257927 ms
Total hot run time: 172327 ms

@hello-stephen

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

query1	0.01	0.01	0.01
query2	0.11	0.05	0.05
query3	0.27	0.14	0.13
query4	1.61	0.14	0.14
query5	0.26	0.22	0.22
query6	1.27	1.06	1.11
query7	0.04	0.01	0.01
query8	0.06	0.04	0.03
query9	0.39	0.31	0.33
query10	0.57	0.55	0.56
query11	0.19	0.15	0.14
query12	0.19	0.14	0.14
query13	0.47	0.48	0.49
query14	1.01	1.03	1.00
query15	0.60	0.59	0.59
query16	0.34	0.34	0.33
query17	1.12	1.12	1.09
query18	0.23	0.22	0.22
query19	2.06	2.02	2.05
query20	0.02	0.01	0.02
query21	15.44	0.22	0.14
query22	4.73	0.05	0.05
query23	16.09	0.32	0.13
query24	3.04	0.44	0.32
query25	0.12	0.04	0.04
query26	0.79	0.22	0.14
query27	0.05	0.04	0.03
query28	3.43	0.97	0.53
query29	12.47	4.38	3.48
query30	0.28	0.15	0.15
query31	2.77	0.58	0.32
query32	3.22	0.61	0.50
query33	3.27	3.22	3.21
query34	15.61	4.25	3.54
query35	3.48	3.56	3.49
query36	0.59	0.43	0.42
query37	0.08	0.06	0.06
query38	0.04	0.04	0.04
query39	0.04	0.03	0.03
query40	0.18	0.16	0.16
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.06	0.04	0.04
Total cold run time: 96.73 s
Total hot run time: 25.41 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 0.00% (0/8) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (5/5) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 74.29% (28502/38365)
Line Coverage 58.14% (310566/534182)
Region Coverage 54.63% (258583/473301)
Branch Coverage 56.13% (112649/200707)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 3.90% (6/154) 🎉
Increment coverage report
Complete coverage report

@HappenLee HappenLee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Jun 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

@morrySnow morrySnow merged commit e4812d1 into apache:master Jun 26, 2026
37 of 38 checks passed
@morrySnow morrySnow deleted the fix-window branch June 26, 2026 09:38
github-actions Bot pushed a commit that referenced this pull request Jun 26, 2026
### What problem does this PR solve?

Related PR: #50559

Problem Summary: nth_value over an upper-bounded/lower-unbounded window
frame such as ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING is
normalized by reversing the order and frame, then evaluating nth_value
with a negative offset over a cumulative frame. The BE nth_value window
state replaced the tracked frame row count on each range update, so
later rows in the cumulative frame could address the wrong row or return
NULL. The fix keeps the cumulative frame row count across range updates,
and FE preserves literal offset typing when negating bigint nth_value
arguments. This adds BE unit coverage for the reversed cumulative
execution path and a regression case comparing nth_value to lead for the
original SQL frame.

### Release note

Fix nth_value results for ROWS BETWEEN CURRENT ROW AND UNBOUNDED
FOLLOWING window frames.
yiguolei pushed a commit that referenced this pull request Jun 26, 2026
…64896)

Cherry-picked from #64864

Co-authored-by: morrySnow <zhangwenxin@selectdb.com>
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/4.0.x dev/4.0.x-conflict dev/4.1.3-merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants