Repository navigation
Description
Description
A finite-width ROWS ... PRECEDING aggregate window is recomputed from scratch for every output row. For SUM, runtime grows approximately with row_count × frame_width, although a sliding aggregate can maintain the frame incrementally.
On 80,000 rows, increasing the frame from 0 to 1,024 rows increases MatrixOne runtime from about 0.05 s to 16.4 s. MySQL 8.0.46 remains about 0.08 s for every tested width. A 600,000-row MatrixOne control with width 1,024 takes 122.3 s.
Environment
- Branch:
main - Commit:
e43d63edb59d1068eadf98613fd2d335e4f786d6 - Deployment: local standalone MatrixOne CN; Connector/J 8.0.33 server-side PreparedStatement
- Control: MySQL 8.0.46, same host and Connector/J
Steps to reproduce
drop database if exists window_frame_perf;
create database window_frame_perf;
create table window_frame_perf.t (
id bigint primary key,
ts timestamp(6),
v int
);
insert into window_frame_perf.t
select result,
timestampadd(microsecond, result, cast('2024-01-01 00:00:00.000000' as datetime(6))),
case when mod(result, 17) = 0 then null else mod(result, 1000) end
from generate_series(1, 80000) g;Prepare and execute the following statement three times for each bound 0, 31, 128, 512, and 1024:
select count(*), sum(ws), min(ws), max(ws)
from (
select sum(coalesce(v, 0)) over (
order by ts, id rows between ? preceding and current row
) ws
from window_frame_perf.t
) q;Actual behavior
All result summaries are correct, but MatrixOne runtime grows linearly with the finite frame width:
| Bound | MatrixOne 3 runs | MySQL 8.0.46 3 runs |
|---|---|---|
| 0 | 53 / 46 / 44 ms | 80 / 78 / 78 ms |
| 31 | 536 / 542 / 563 ms | 79 / 84 / 81 ms |
| 128 | 2088 / 2089 / 2086 ms | 81 / 80 / 79 ms |
| 512 | 8290 / 8110 / 8188 ms | 85 / 79 / 80 ms |
| 1024 | 16529 / 16375 / 16353 ms | 80 / 81 / 80 ms |
For bound 1024, both products return the same summary:
count=80000, sum(ws)=38224384305, min(ws)=1, max(ws)=494105
An additional 600,000-row run took 122,266 ms at bound 1024 versus 3,580 ms at bound 31. CN RSS was sampled during this scale run: 843,056 KiB before, 1,433,072 KiB peak, and 1,195,152 KiB after cleanup; the CN did not restart.
Expected behavior
Fixed-size cumulative aggregates such as SUM should maintain a bounded sliding state (add the entering row and remove the leaving row), or use another algorithm whose work does not replay the full frame for every output row. Runtime should not scale as O(row_count × frame_width) for this query shape.
Stability and controls
- Reproducer: 3/3 at every frame width on the latest official
main - MySQL control: 3/3 with identical values; 78–85 ms across all widths
- Result oracle: independent Java sliding-window calculation; exact count/sum/min/max asserted
- Prepared mode: actual Connector/J
ServerPreparedStatement, reused while changing the frame parameter - Service state: no panic, OOM, or restart; database removed after both success and failure paths
Evidence
- Full reproducer:
WindowBoundedFramePerfProbe.java - Scale/control probe:
WindowTemporalScaleProbe.java - Exact timing and result summaries are included above.
Code analysis
pkg/sql/colexec/window/window.go, processAggregateFuncRange, builds the interval for each output row and calls Fill for every row in that interval. This is O(N × W) for a bounded W PRECEDING frame.
The linear cumulative path added by PR #27006 only applies when the frame starts at the partition boundary (unbounded, or a finite bound covering the entire partition). It therefore fixes #23107 but intentionally does not handle a normal finite sliding frame such as 1,024 preceding rows.
Regression coverage
After the implementation is optimized:
- add a focused Window benchmark covering several finite frame widths and asserting non-linear growth is eliminated;
- retain a small deterministic SQL correctness case for Prepared frame parameters;
- keep the 80,000+ row timing/scale gate in nightly big-data or performance coverage rather than BVT.
Related
- Performance Issue: Window functions with large ROWS values cause query timeout #23107 / fix(window): evaluate cumulative sum frames linearly #27006: large bound covering the whole partition; fixed by the cumulative-frame path, not a duplicate
- [Tech Request]: Improve performance of range frame in over() window function #12961 and [Bug]: window function: frame range's poor performance. #13008:
RANGEframe performance, while this issue is finite-widthROWS
Activity
Ariznawlll commentedon Aug 26, 2026
测试版本
main5bc051abc44f34ccb6813e2a0bb5585d5a1db67e原问题验证
按 Issue 原 SQL 创建 80,000 行数据,复用同一个
com.mysql.cj.jdbc.ServerPreparedStatement,依次绑定 frame bound0/31/128/512/1024,每档执行 3 次。耗时已不再随 frame width 线性增长:1024的结果摘要仍为count=80000, sum=38224384305, min=1, max=494105,与 Issue oracle 完全一致。Happy Path 覆盖
290/275/304 ms,bound 1024 为286/290/297 ms,两档耗时保持同一量级。SELECT 1成功。Unhappy Path 覆盖
白盒验证
window/aggexec 的 bounded sliding SUM、prepared runtime bound、跨输出 batch、分区重置、NULL、INT64、DECIMAL64、取消和非连续输出保护测试连续执行 3 轮通过。
回归测试
测试证据
Connector/J 探针确认 statement class 为
ServerPreparedStatement,80,000 行和 600,000 行所有执行均输出完整摘要;修复后的 1024 frame 相比 Issue 中约 16.4 秒已降至 40–51 ms。测试结论
测试通过。
Ariznawlll commentedon Aug 26, 2026
测试版本
main5bc051abc44f34ccb6813e2a0bb5585d5a1db67emysql-connector-python 9.7.0binary prepared statement原问题验证
按 issue 中的数据分布生成 600,000 行,复用同一个 binary prepared statement,分别绑定
31 PRECEDING和1024 PRECEDING,每个 bound 执行 3 次。查询均返回精确一致的count/sum/min/max,宽窗口相对窄窗口的 P50 比率为0.992,未再随 frame width 线性增长。Happy Path 覆盖
31 PRECEDING:3 次耗时314.483 / 332.725 / 327.890 ms,P50327.890 ms;结果为(600000, 9025830114, 1, 30489)。1024 PRECEDING:3 次耗时325.328 / 320.797 / 328.605 ms,P50325.328 ms;结果为(600000, 288797684381, 1, 494105)。SELECT 1成功;测试数据库在退出路径中完成清理。Unhappy Path 覆盖
1024/31P50 比率超过3.0时立即失败,不会把原来的O(N×W)行为记录为成功基线。白盒验证
不适用。本次补充的是 binary prepared 协议与 600,000 行规模下的黑盒性能门禁;窗口算法白盒覆盖由 MatrixOne 仓库已有测试负责。
回归测试
big_data):https://github.com/matrixorigin/mo-nightly-regression/pull/1509main):https://github.com/matrixorigin/mo-nightly-regression/pull/1510issue_27352,只运行33 Issue 27352 Bounded ROWS Window,无需执行整套 1Y 数据准备。测试证据
maincommit:5bc051abc44f34ccb6813e2a0bb5585d5a1db67eaf6878e3cff2639ed5acec50ad595dd9a81167afb1cc5b17a633821e67f0ef848659e09bd232bc6dwide_to_narrow_p50_ratio=0.992,prepared_connection_recovery=true,pass=true测试结论
测试通过。