Skip to content

[Feature Request]: support sub-second units in Time Window aggregation #26983

Closed

Description

@XuPeng-SH

Summary

MatrixOne's native Time Window aggregation cannot express sub-second windows. The SQL grammar accepts MICROSECOND as a time unit, but the Time Window executor only supports SECOND, MINUTE, HOUR, and DAY.

This is a time-series capability gap for high-frequency telemetry, industrial sensor, market-data, and trace workloads. Partition rotation is not a substitute for query-time bucketing, and partition support should not be assumed as a workaround.

Environment

  • Repository: matrixorigin/matrixone
  • Branch: main
  • Commit: c3ba9c7df14388956cb38d78681c6c35b75c42b8
  • Host used for capability validation: Debian x86_64, 10.222.1.55
  • SQL endpoint during validation: 127.0.0.1:6001

Reproduction

CREATE TABLE ts_hf (
  event_ts TIMESTAMP(6),
  device_id BIGINT,
  value DOUBLE
);

INSERT INTO ts_hf VALUES
  ('2026-08-12 10:00:00.000100', 1, 10),
  ('2026-08-12 10:00:00.000900', 1, 20),
  ('2026-08-12 10:00:00.001100', 1, 30);

SELECT _wstart, _wend, COUNT(*), AVG(value)
FROM ts_hf
INTERVAL(event_ts, 1000, MICROSECOND);

Observed result:

ERROR 20105 (HY000): not supported: Time Window aggregate only support SECOND, MINUTE, HOUR, DAY as the time unit

The grammar currently parses INTEGRAL time_unit, and time_unit includes MICROSECOND, but pkg/sql/colexec/timewin/types.go::calcDatetime rejects every unit outside SECOND/MINUTE/HOUR/DAY.

A decimal-second form is not an alternative because the Time Window grammar requires an integer interval value:

-- parser rejection
SELECT _wstart, _wend, COUNT(*)
FROM ts_hf
INTERVAL(event_ts, 0.001, SECOND);

Expected behavior

Support fixed-duration sub-second windows in the native Time Window operator, at minimum:

INTERVAL(event_ts, 1000, MICROSECOND)
SLIDING(100, MICROSECOND)

The behavior should compose with existing Time Window capabilities:

  • _wstart / _wend
  • tumbling and sliding windows
  • GAPFILL
  • FILL(NULL|PREV|NEXT|LINEAR|VALUE)
  • PARTITION BY
  • TIMESTAMP(6) / DATETIME(6) boundary correctness

Why this is a real time-series gap

DATE_TRUNC now covers calendar and fixed rollups down to one second, but it does not provide arbitrary sub-second buckets, sliding windows, or native gap filling. generate_series can produce timestamps but does not replace the Time Window operator for aggregation.

This is independent of table partitioning: partition lifecycle cannot implement 100 µs / 1 ms aggregation windows.

Related issues

Activity

  1. added
    severity/s0
    on Aug 11, 2026
  2. added a commit that references this issue on Aug 14, 2026
  3. Ariznawlll commented on Aug 15, 2026

    @Ariznawlll
    Collaborator

    验证 #26983 时发现一个独立问题:对 MICROSECOND Time Window 生成的 _wstart/_wend 执行 TIMESTAMPDIFF(MICROSECOND, _wstart, _wend) 会在当前 main(a1e161ad3e0fc83cabfc66db8b4d5419d16c9ee4)稳定触发 ERROR 20101 的 TIMESTAMP/DATETIME 类型 panic,单机和 2-CN proxy 均为 3/3。

    已新建关联 bug:#27189。原始 MICROSECOND 聚合路径本身可通过,本问题单独跟踪窗口边界类型处理。

  4. Ariznawlll commented on Aug 15, 2026

    @Ariznawlll
    Collaborator

    补充验收结果(最新 main,commit a1e161a):

    已通过的功能覆盖:

    • MOTR 新增 suites/14_issue_regression/t/issue_26983_microsecond_edges.test;
    • 覆盖 TIMESTAMP(6) 精确边界、TIMESTAMP(3)、DATETIME(6)、MICROSECOND tumbling/sliding、FILL(NULL/PREV)、0 interval、0 sliding 和 MONTH 非法参数;
    • MOTR 重复执行 3 次,57/57 条 SQL 通过;
    • DATETIME(3/6) 生成窗口边界执行 TIMESTAMPDIFF(MICROSECOND, _wstart, _wend) 返回 1000,正常。

    仍存在的边界类型问题:

    • TIMESTAMP、TIMESTAMP(3)、TIMESTAMP(6) 生成的 _wstart/_wend 直接执行 TIMESTAMPDIFF,均稳定 3/3 触发 ERROR 20101:panic type mismatch: casting TIMESTAMP vector to []types.Datetime;
    • DATE_FORMAT(_wstart)、TIMESTAMPADD(..., _wstart) 和 _wstart + INTERVAL 也触发同类 panic;
    • 显式 CAST、比较、UNIX_TIMESTAMP 可以通过,说明问题集中在生成的 TIMESTAMP 边界列被日期函数按 DATETIME 读取。

    该问题已在关联 bug #27189 跟踪。当前 MICROSECOND 聚合主路径已通过,但 TIMESTAMP 边界类型兼容性仍未完成,建议修复或明确拆分后再关闭本 issue。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/featureseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions