You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Prepared window frame rejects parameter markers for PRECEDING and FOLLOWING #25993
Searched for prepared window-frame parameter markers and ? PRECEDING / ? FOLLOWING. No matching issue was found.
Branch Name
main
Commit ID
c0486a2446c84c6dd6bf142494fe85243877ddc5
Other Environment Information
MatrixOne: 8.0.30-MatrixOne-v1.3.0
MySQL comparison: 8.0.45
SQL-level PREPARE / EXECUTE through the mysql client
Actual Behavior
MatrixOne supports a prepared window query when the ROWS frame bounds are integer literals, but rejects the equivalent MySQL-compatible parameterized form during PREPARE:
ERROR 1105 (HY000): ... syntax error ... near " ? PRECEDING AND ? FOLLOWING) ..."
The literal control returns the expected running-window sums in both MatrixOne and MySQL:
1 30
2 60
3 50
MySQL 8.0.45 returns the same result for the parameterized frame. MatrixOne reproduced the prepare-time rejection 3/3 times.
Expected Behavior
Parameter markers should be accepted for ROWS frame bounds inside a prepared statement and bound at EXECUTE time, consistent with MySQL.
Steps to Reproduce
DROPDATABASE IF EXISTS ps_window_param;
CREATEDATABASEps_window_param;
USE ps_window_param;
CREATETABLEe(id INTPRIMARY KEY,n INT);
INSERT INTO e VALUES(1,10),(2,20),(3,30);
-- Literal prepared control succeeds.
PREPARE literal_frame FROM'SELECT id,SUM(n) OVER (ORDER BY id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM e ORDER BY id';
EXECUTE literal_frame;
-- Equivalent parameterized form is rejected by MatrixOne.
PREPARE parameter_frame FROM'SELECT id,SUM(n) OVER (ORDER BY id ROWS BETWEEN ? PRECEDING AND ? FOLLOWING) FROM e ORDER BY id';
SET @before=1,@after=1;
EXECUTE parameter_frame USING @before,@after;
Additional Information
The MySQL grammar in pkg/sql/parsers/dialect/mysql/mysql_sql.y restricts frame_bound and frame_bound_start to num_literal or interval_expr. A parameter marker is therefore rejected before it can be represented in the prepared plan. The window binder also currently evaluates finite frame bounds as constants while building the plan.
Confirmed on current-main baseline e15943929885c2c5c83daed90f0f8caeb9a1f0d0. This is a real compatibility gap, but it is not only a parser omission.
The grammar rejects parameter markers in finite frame bounds; the planner then eagerly evaluates frame bounds as constants; the window executor assumes a literal unsigned-value carrier; and prepared-parameter collection/reset does not traverse the window specification. A grammar-only change would merely move the failure downstream and could make cached executions reuse the wrong bound.
No partial PR proposed. Complete support needs parser acceptance, WindowSpec parameter discovery/reset, and once-per-EXECUTE frame evaluation and validation with a stable cache/reuse contract. Tests must include repeated executions with different bounds, zero/negative/NULL/fractional/overflow values, wrong argument counts, ROWS/RANGE, and remote execution.
Implemented against current main (0d7eeb38b4) in ready-for-review PR #26094: #26094
The fix covers parser/binder preservation, prepared-parameter traversal and alias-safe renumbering, per-Prepare immutable ROWS-bound materialization, Reset/Free lifecycle, invalid-value handling, process-codec coverage, and a distributed SQL regression. Dynamic RANGE and interval bounds remain explicitly unsupported. Local affected-package, race, build, and vet checks passed; CI has started and is not being waited on here.
Activity
LeftHandCold commentedon Jul 22, 2026
Confirmed on current-main baseline
e15943929885c2c5c83daed90f0f8caeb9a1f0d0. This is a real compatibility gap, but it is not only a parser omission.The grammar rejects parameter markers in finite frame bounds; the planner then eagerly evaluates frame bounds as constants; the window executor assumes a literal unsigned-value carrier; and prepared-parameter collection/reset does not traverse the window specification. A grammar-only change would merely move the failure downstream and could make cached executions reuse the wrong bound.
No partial PR proposed. Complete support needs parser acceptance, WindowSpec parameter discovery/reset, and once-per-
EXECUTEframe evaluation and validation with a stable cache/reuse contract. Tests must include repeated executions with different bounds, zero/negative/NULL/fractional/overflow values, wrong argument counts, ROWS/RANGE, and remote execution.LeftHandCold commentedon Jul 23, 2026
Implemented against current
main(0d7eeb38b4) in ready-for-review PR #26094: #26094The fix covers parser/binder preservation, prepared-parameter traversal and alias-safe renumbering, per-
Prepareimmutable ROWS-bound materialization, Reset/Free lifecycle, invalid-value handling, process-codec coverage, and a distributed SQL regression. Dynamic RANGE and interval bounds remain explicitly unsupported. Local affected-package, race, build, and vet checks passed; CI has started and is not being waited on here.fix(plan): preserve prepared aggregate parameters (#26042)
fix(window): support prepared ROWS frame bounds (#26094)
LeftHandCold commentedon Jul 24, 2026
fixed
Ariznawlll commentedon Jul 27, 2026
最新 main 验证结果:通过
测试版本
main@8c9bb66898afa74f8b231e1915d99489ae8a0da7测试 SQL
在同一个 prepared statement 上依次使用
(1,1)、(0,2)、(2,0)三组 frame bounds,检查重复执行是否会错误复用上一次参数。实际结果
(1,1)返回窗口和:30, 60, 90, 70。(0,2)返回:60, 90, 70, 40。(2,0)返回:10, 30, 60, 90。ERROR 20203: invalid argument cast to uint64。ERROR 20301: window frame bound cannot be NULL。结论
prepared ROWS frame 已支持参数标记、重复换参和非法值校验,原 prepare-time 语法拒绝问题已修复。
Ariznawlll commentedon Jul 27, 2026
motr 黑盒回归
该问题已加入 matrixorigin/motr#66。
在 MatrixOne
main@8c9bb66898afa74f8b231e1915d99489ae8a0da7上连续执行 3 轮,结果稳定通过。fix(plan): preserve prepared aggregate parameters (matrixorigin#26042)
fix(window): support prepared ROWS frame bounds (matrixorigin#26094)
fix(plan): preserve prepared aggregate parameters (matrixorigin#26042)
fix(window): support prepared ROWS frame bounds (matrixorigin#26094)
fix(plan): preserve prepared aggregate parameters (matrixorigin#26042)
fix(window): support prepared ROWS frame bounds (matrixorigin#26094)