Repository navigation
Description
Summary
MatrixOne's time-window operator interval(timestamp, n, unit) mis-buckets fractional-second timestamps. Values at or after .500000 seconds before a window boundary are rounded into the next window instead of being floored into the half-open window that contains the timestamp.
This is a blocking correctness issue for time-series feature acceptance: queries complete successfully and the server stays healthy, but daily/hourly/second aggregates are silently wrong.
Environment
- Repository:
matrixorigin/matrixone - Branch:
main - Commit:
c3ba9c7df14388956cb38d78681c6c35b75c42b8 - Host: Debian x86_64,
10.222.1.55 - SQL endpoint:
127.0.0.1:6001 - Test database:
ts_validation_20260812 - Test artifact:
mo-servicewithgo version -mprovenance for the commit above
Minimal reproduction
DROP TABLE IF EXISTS ts_min;
CREATE TABLE ts_min (
id INT NOT NULL PRIMARY KEY,
event_ts TIMESTAMP(6) NOT NULL,
value INT NOT NULL
);
INSERT INTO ts_min VALUES
(1, '2024-02-29 23:59:59.499999', 1),
(2, '2024-02-29 23:59:59.500000', 2),
(3, '2024-02-29 23:59:59.999999', 3);
-- All three rows are in the half-open day [Feb 29, Mar 1).
SELECT COUNT(*)
FROM ts_min
WHERE event_ts >= '2024-02-29 00:00:00.000000'
AND event_ts < '2024-03-01 00:00:00.000000';
SELECT _wstart, _wend, COUNT(*), SUM(value), MIN(id), MAX(id)
FROM ts_min
WHERE event_ts >= '2024-02-29 00:00:00.000000'
AND event_ts < '2024-03-01 00:00:00.000000'
INTERVAL(event_ts, 1, day);Direct range result:
COUNT(*)
3
Actual interval result:
_wstart _wend COUNT SUM MIN MAX
2024-02-29 00:00:00.000000 2024-03-01 00:00:00.000000 1 1 1 1
2024-03-01 00:00:00.000000 2024-03-02 00:00:00.000000 2 5 2 3
Expected result is one Feb 29 bucket with COUNT=3, SUM=6, MIN=1, MAX=3. The .500000 and .999999 rows are incorrectly placed in the Mar 1 bucket even though the predicate explicitly excludes Mar 1.
Additional validation
- The same boundary behavior was reproduced with
DATETIME(6). interval(..., 1, hour)andinterval(..., 1, second)also move.500000/later fractional values to the next bucket.DATE_TRUNC(day/hour/second, event_ts)floors correctly, and raw half-open range predicates return the correct rows.- Inserts, reads, bulk writes, DML transactions/rollback, index scans, concurrent readers/writers, and restart durability all passed; the failure is isolated to time-window bucketing.
- No panic, crash, deadlock, or server-log error occurred. This is a silent data-correctness failure.
Impact
Any time-series query using interval for rollups can report incorrect per-window counts and aggregates for normal sub-second event data. This affects daily/hourly/second rollups and can make dashboards, downsampling, and alert calculations wrong without an error.
Suspected area
pkg/sql/colexec/timewin/timewin.go computes window boundaries using integer modulo (val - val%interval). The observed threshold suggests the timestamp-to-window type conversion rounds fractional seconds before that modulo operation. This is a hypothesis to confirm during fixing.
Workaround
Use raw half-open range predicates or DATE_TRUNC-based grouping where applicable; these controls returned the expected bucket for the repro above.
Activity
XuPeng-SH commentedon Aug 11, 2026
Follow-up validation with a standard IoT/TSBS-like telemetry workload on commit
c3ba9c7df14388956cb38d78681c6c35b75c42b8(10.222.1.55):cpu_usage,temperature), one-minute samples over 24 hours: 144,000 rows.TIMESTAMP(6)points fordevice-001/cpu_usage, including08:59:59.500000and08:59:59.999999.[08:00,09:00)returned 63 rows;DATE_TRUNC('hour', event_ts)kept all 63 in the 08:00 bucket.interval(event_ts, 1, hour)query returned 61 rows in 08:00 and moved the two fractional boundary points to 09:00.fill(null)/fill(prev)), sliding-window, concurrent ingest/read, upsert, and restart-durability checks otherwise passed.This confirms the issue is reproducible in a normal telemetry workload, not only in the three-row minimal repro.
XuPeng-SH commentedon Aug 11, 2026
Additional boundary matrix on the same commit:
1969-12-31 23:59:59.499999,.500000,.999999, a raw range andDATE_TRUNCreturn all 3 rows in the same second/day, whileinterval(...,1,second/day)returns 1 row in the prior bucket and 2 rows in the next bucket.[00:00,00:01),DATE_TRUNC('minute', ...)returns all 5 fractional rows together, whileinterval(...,1,minute)returns 3 in00:00and 2 in00:01.fix interval time windows (#27000)
Ariznawlll commentedon Aug 14, 2026
测试版本
mainde40fe49fd105bd4d77bde8989369cec1fe65c76原问题验证
复跑 Issue 的闰日
TIMESTAMP(6)边界:23:59:59.000000/.499999/.500000/.999999均保留在 2 月 29 日的半开区间内,日窗口精确为COUNT=4, SUM=10, MIN(id)=1, MAX(id)=4,00:00:00.000000单独进入 3 月 1 日,不再发生.500000后被舍入到下一桶的问题。完整矩阵及 MOTR 定向回归连续执行 3 轮均通过。Happy Path 覆盖
TIMESTAMP(6)的秒、分钟、天窗口,结果分别与原始半开范围及DATE_TRUNCoracle 一致。.000000。DATETIME(6),.499999/.500000/.999999均正确 floor 到前一秒。Unhappy Path 覆盖
SUM(value)=15,同一会话继续可用。白盒验证
exact main 上
TestQueryBuilder_bindTimeWindowTruncatePreservesFractionalScale连续 3 轮通过;该修复为确定性时间精度/类型转换路径,本轮不单独增加 race gate。回归测试
已加入 MOTR PR #109:
issue_26975_time_window_fractional_boundary.test。定向--repeat 3为 3/3 通过;完整14_issue_regression中本用例通过。该缺陷由数值精度转换触发,与数据规模无关,不需要大数据量回归。测试证据
d72bc6ad7e2d65dfc408c939a0eeb15fda3d8d5f测试结论
测试通过。
fix interval time windows (matrixorigin#27000)
fix interval time windows (matrixorigin#27000)
fix interval time windows (matrixorigin#27000)