Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- MatrixOne: local single-CN deployment built from the commit above
- MySQL control: MySQL 8.0
- Client: MySQL Connector/J 8.0.33
- Verification: 3 independent roundsActual Behavior
When an ORDER BY is present and the frame clause is omitted, MatrixOne evaluates LAST_VALUE and NTH_VALUE over the entire partition. This is equivalent to ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING, rather than the default ordered frame.
MatrixOne result:
1 | 40 | 30
2 | 40 | 30
3 | 40 | 30
4 | 40 | 30
The same query returns the expected peer-aware running frame in MySQL:
1 | 20 | NULL
2 | 20 | NULL
3 | 30 | 30
4 | 40 | 30
An explicit RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW produces the expected MySQL-compatible result in MatrixOne. This isolates the problem to the omitted-frame path rather than value-function execution itself.
Expected Behavior
For an ordered window with no explicit frame, frame-sensitive value functions should use RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, consistent with MySQL's documented default-frame behavior.
Steps to Reproduce
DROP DATABASE IF EXISTS window_default_frame_repro;
CREATE DATABASE window_default_frame_repro;
USE window_default_frame_repro;
CREATE TABLE t(id INT PRIMARY KEY, o INT, v INT);
INSERT INTO t VALUES
(1, 1, 10),
(2, 1, 20),
(3, 2, 30),
(4, 3, 40);
-- Wrong in MatrixOne: omitted frame is expanded to the full partition.
SELECT id,
LAST_VALUE(v) OVER (ORDER BY o) AS lv,
NTH_VALUE(v, 3) OVER (ORDER BY o) AS nv
FROM t
ORDER BY id;
-- Control: correct in MatrixOne and MySQL.
SELECT id,
LAST_VALUE(v) OVER (
ORDER BY o RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS lv,
NTH_VALUE(v, 3) OVER (
ORDER BY o RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS nv
FROM t
ORDER BY id;Stability, controls, and recovery
- Reproduced 3/3 on the commit above.
- MySQL returned the expected result 3/3.
- The explicit-frame control returned the expected result 3/3 in both systems.
- The query is read-only and leaves the connection usable.
Root-cause evidence
pkg/sql/plan/window_binder.go rewrites every value window function without an explicit frame to ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING. That override is appropriate for functions such as LAG/LEAD, which operate independently of a frame, but changes the semantics of frame-sensitive LAST_VALUE and NTH_VALUE.
Suggested regression placement
Add a BVT under test/distributed/cases/window/ covering omitted versus explicit default frames, peer rows, and both LAST_VALUE and NTH_VALUE.
Related issues
- [Performance]: Value window functions (lag/lead/first_value/last_value/nth_value) have O(n²) memory hotspot #23962 concerns value-window performance and is not the same correctness problem.
Activity
fix: honor default frames for value window functions (#28152)
Ariznawlll commentedon Sep 5, 2026
测试版本
mainfa829e5c505520e4bd429d283c78157781b4de72原问题验证
在 3 轮独立执行中复测
LAST_VALUE/NTH_VALUE默认 window frame。原有 peer-group 语义、显式RANGEframe 和完整分区对照均返回预期值。Happy Path 覆盖
RANGE、完整分区和降序窗口均正确。Unhappy Path 覆盖
白盒验证
不适用:该问题为公开 SQL window 语义。
回归测试
已加入 MOTR:
suites/14_issue_regression/t/issue_27341_default_value_frame.test。PR:https://github.com/matrixorigin/motr/pull/145 。该仓库当前没有可触发的 PR 回归 workflow,状态检查为空;回归文件已完成本地语法和相关 suite 校验。测试证据
129 TKE 实测 3/3,覆盖 97 项断言;测试数据库已清理。
测试结论
测试通过。
fix: honor default frames for value window functions (matrixorigin#28152
fix: honor default frames for value window functions (matrixorigin#28152
fix: honor default frames for value window functions (matrixorigin#28152
daviszhen commentedon Oct 16, 2026
v4.2.5 release-specific reproduction (arm64)
Independent replay on the official
matrixorigin/matrixone:latestimage — arm64/linux,VERSION()=8.0.30-MatrixOne-v4.2.5, single-node standalone, Apple M5 host, mysql 8.4 CLI. This comment does not assert anything about currentmain; it only records that the behaviour is still present in this release image.Still reproducible for
LAST_VALUEwith an omitted frame clause. Data(id, amt)= 1..4 → 10.50, 20.25, 30.75, 40.00:Confirmed working on this release, which narrows the scope to the default frame of
LAST_VALUEonly:last_value(amt) OVER (ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)→ matches MySQL ✅first_value/nth_valuewith explicit frames → matches MySQL ✅max(amt) OVER (ORDER BY id)andcount(*) OVER (ORDER BY id)without a frame clause → matches MySQL ✅Workaround: write the frame clause explicitly. Impact matters because "compare with the latest value in the group" is a very common reporting pattern and currently returns silently wrong values.