Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
249a458ba567b26d1818fb0496b449135cb05ef2
This was the current GitHub main head immediately before submission. The
runtime reproducer was also validated on PR #27568 head 131ca9c; that PR
changes the uint64 / BIT path, while the signed integer path remains
unchanged.
Other Environment Information
- Hardware parameters: local development machine
- OS type: macOS arm64
- Deployment: local standalone MatrixOne, direct CN SQL endpoint
- Client: MySQL text protocol at 127.0.0.1:16001
- Server version: 8.0.30-MatrixOne-v1.3.0
- Executable: mo-service-fix-27565-131ca9c (PR #27568 head)Actual Behavior
For a signed BIGINT ORDER BY key, a finite Window RANGE bound silently
wraps when it crosses INT64_MAX or INT64_MIN. The wrapped search key is
placed at the opposite end of the signed domain, so a frame that must contain
its current row becomes empty.
Both directions are affected:
RANGE BETWEEN CURRENT ROW AND 1 FOLLOWINGat
9223372036854775807returnsCOUNT(*) = 0,SUM(v) = NULL.RANGE BETWEEN 1 PRECEDING AND CURRENT ROWat
-9223372036854775808returnsCOUNT(*) = 0,SUM(v) = NULL.
The minimal queries reproduced identically in three consecutive runs.
A 500,010-row confirmation used 23,810 independent partitions of 21 rows.
Each partition contained one INT64_MIN key, nineteen zero keys, and one
INT64_MAX key. An independent reference found:
INT64_MAX, CURRENT ROW ... 1 FOLLOWING: 23,810 wrong rows
INT64_MIN, 1 PRECEDING ... CURRENT ROW: 23,810 wrong rows
ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING: 0 wrong rows
Two complete scale repetitions returned identical counts. Zero-offset
RANGE, interior signed keys, and ROWS controls return correct results.
This is different from #27565 / PR #27568, which cover BIGINT UNSIGNED and
BIT. It is also different from #27350, which concerns temporal Window bounds
that fail with error 1690. This signed defect reproduces on the #27568 PR-head
executable itself.
Expected Behavior
A finite Window RANGE frame includes its current row. A mathematical upper
bound above INT64_MAX is beyond every key in an ascending partition, and a
lower bound below INT64_MIN is before every key. Neither bound should wrap
to the opposite endpoint.
For both boundary rows, the expected result is:
COUNT(*) = 1
SUM(v) = current row's v
Steps to Reproduce
CREATE DATABASE mo_i64_range_overflow_repro;
USE mo_i64_range_overflow_repro;
CREATE TABLE t (
id INT PRIMARY KEY,
k BIGINT NOT NULL,
v INT NOT NULL
);
INSERT INTO t VALUES
(1, -9223372036854775808, 10),
(2, 0, 20),
(3, 9223372036854775807, 30);
SELECT id, k,
COUNT(*) OVER (
ORDER BY k
RANGE BETWEEN CURRENT ROW AND 1 FOLLOWING
) AS c,
SUM(v) OVER (
ORDER BY k
RANGE BETWEEN CURRENT ROW AND 1 FOLLOWING
) AS s
FROM t
ORDER BY id;
SELECT id, k,
COUNT(*) OVER (
ORDER BY k
RANGE BETWEEN 1 PRECEDING AND CURRENT ROW
) AS c,
SUM(v) OVER (
ORDER BY k
RANGE BETWEEN 1 PRECEDING AND CURRENT ROW
) AS s
FROM t
ORDER BY id;Actual results at the affected rows:
FOLLOWING query:
id k c s
3 9223372036854775807 0 NULL
PRECEDING query:
id k c s
1 -9223372036854775808 0 NULL
Possible Root Cause
pkg/sql/colexec/window/window.go, in the signed integer branches of
searchLeft and searchRight, computes frame search keys with unchecked
fixed-width arithmetic:
col[rowIdx] + c
col[rowIdx] - cAt signed extrema these operations wrap before genericSearchLeft /
genericSearchRight runs. Current GitHub main still contains this arithmetic
in the int8, int16, int32, and int64 branches.
The out-of-domain bound should map to the correct before-domain or after-domain
insertion boundary, with ASC/DESC handled explicitly, rather than manufacturing
a wrapped key. PR #27568's explicit out-of-domain handling for uint64 is a
close structural precedent.
Suggested regression coverage:
- signed integer minima/maxima for
T_int8,T_int16,T_int32, andT_int64 - ASC and DESC
- PRECEDING and FOLLOWING
- zero and nonzero offsets
- NULL peers and multi-row peer groups
COUNT,SUM, and empty-frame-sensitive aggregates
Activity
fix(window): handle signed integer range bounds (#27578)
Lundomn commentedon Sep 7, 2026
QA 转测(2026-09-07)
请在本 Issue 记录实际测试版本/环境、通过或失败结论、未覆盖项及补测要求。按流程,QA 明确通过后再关闭 Issue;如发现失败或回归请保持 open 并反馈复现信息。
Ariznawlll commentedon Sep 7, 2026
测试版本
mainbcd5ed833b5400fe95f322e4028adb2bde3de0a46001原问题验证
-9223372036854775808、0、9223372036854775807三个边界值。RANGE BETWEEN CURRENT ROW AND 1 FOLLOWING,再执行RANGE BETWEEN 1 PRECEDING AND CURRENT ROW。Happy Path 覆盖
1、求和10/20/30;最小值和最大值未发生溢出或空帧。Unhappy Path 覆盖
白盒验证
不适用。本轮验证公开窗口 SQL 语义,未使用内部故障注入。
回归测试
已加入 MOTR PR #145:
suites/14_issue_regression/t/issue_27574_signed_bigint_range.test。测试证据
stmts=24 ok=24 fail=0。测试结论
测试通过。
fix(window): handle signed integer range bounds (matrixorigin#27578)
fix(window): handle signed integer range bounds (matrixorigin#27578)
fix(window): handle signed integer range bounds (matrixorigin#27578)