Skip to content

[Bug]: GROUP_CONCAT loses temporal scale and exposes TIMESTAMP in internal UTC format #28657

Closed

Description

@Ariznawlll

Description

GROUP_CONCAT bypasses MatrixOne's normal temporal display conversion:

  • DATETIME(p) and TIME(p) values lose all fractional-second digits when passed directly to the aggregate.
  • TIMESTAMP(p) values are rendered as internal UTC timestamps with a UTC suffix, ignoring the session time zone used by direct SELECT and CAST.

The stored values and explicit CAST(... AS CHAR) results are correct. Only the aggregate's direct temporal formatting changes the data.

Environment

  • Branch: main
  • Commit: e7d46d6dfb27696211ca828c55e245d3bd1b634d
  • Deployment: local standalone (1 CN / 1 TN / 1 LogService)
  • Oracle: MySQL 8.3.0, isolated local instance

Steps to reproduce

drop database if exists gc_fractional_temporal;
create database gc_fractional_temporal;
use gc_fractional_temporal;

set session time_zone = '+08:00';
create table src (
  id int primary key,
  dt3 datetime(3),
  dt6 datetime(6),
  tm3 time(3),
  tm6 time(6),
  ts3 timestamp(3),
  ts6 timestamp(6)
);
insert into src values
  (1, '2024-01-02 03:04:05.120', '2024-01-02 03:04:05.123456',
      '12:34:56.120', '12:34:56.123456',
      '2024-01-02 03:04:05.120', '2024-01-02 03:04:05.123456'),
  (2, '2024-01-03 04:05:06.007', '2024-01-03 04:05:06.000007',
      '-01:02:03.004', '-01:02:03.000004',
      '2024-01-03 04:05:06.007', '2024-01-03 04:05:06.000007');

select id, dt3, dt6, tm3, tm6, ts3, ts6 from src order by id;
select group_concat(dt3 order by id separator '|') from src;
select group_concat(dt6 order by id separator '|') from src;
select group_concat(tm3 order by id separator '|') from src;
select group_concat(tm6 order by id separator '|') from src;
select group_concat(ts3 order by id separator '|') from src;
select group_concat(cast(ts3 as char) order by id separator '|') from src;

set session time_zone = '+00:00';
select id, ts3, cast(ts3 as char) from src order by id;
select group_concat(ts3 order by id separator '|') from src;
select group_concat(cast(ts3 as char) order by id separator '|') from src;

Actual behavior

Representative MatrixOne results:

dt3: 2024-01-02 03:04:05|2024-01-03 04:05:06
dt6: 2024-01-02 03:04:05|2024-01-03 04:05:06
tm3: 12:34:56|-01:02:03
tm6: 12:34:56|-01:02:03

TIMESTAMP at session +08:00:
direct/cast: 2024-01-02 03:04:05.120
GROUP_CONCAT: 2024-01-01 19:04:05.120000 UTC

TIMESTAMP at session +00:00:
direct/cast: 2024-01-01 19:04:05.120
GROUP_CONCAT: 2024-01-01 19:04:05.120000 UTC

The aggregate TIMESTAMP string is invariant across session time-zone changes and exposes the internal UTC representation.

Expected behavior

Direct temporal arguments should use the same textual conversion as the corresponding value in the current session:

  • preserve the declared fractional-second scale for DATETIME(p), TIME(p), and TIMESTAMP(p);
  • convert TIMESTAMP through the active session time zone;
  • do not append an internal UTC suffix.

MySQL 8.3.0 produces the same text as CAST(... AS CHAR) for all these probes.

Stability and controls

  • Reproducer: 3/3 for scale 3 and 6 across DATETIME, TIME, and TIMESTAMP.
  • Time-zone matrix: 3/3 at +08:00 and +00:00.
  • Storage control: direct SELECT preserves every inserted fractional digit.
  • Conversion control: GROUP_CONCAT(CAST(value AS CHAR)) preserves scale and session time-zone conversion in MatrixOne.
  • Scale-0 control: DATETIME, TIME, and MySQL TIMESTAMP values without fractions render as expected.
  • MySQL 8.3.0 oracle: direct aggregate and explicit-cast aggregate results are identical in 3/3 runs.
  • Failure atomicity: all probes are read-only and leave source rows unchanged.

Evidence

The complete result files for all three MatrixOne runs are byte-identical, as are all three MySQL runs. Representative output is included above.

Code analysis

pkg/sql/colexec/aggexec/agg_payload.go::writeGroupConcatData formats temporal payloads directly:

case types.T_datetime:
    return writeValue(util.UnsafeFromBytes[types.Datetime](data).String())
case types.T_timestamp:
    return writeValue(util.UnsafeFromBytes[types.Timestamp](data).String())
case types.T_time:
    return writeValue(util.UnsafeFromBytes[types.Time](data).String())

These calls have no declared scale and no session time-zone context. They therefore differ from the normal expression/vector-to-text conversion used by direct SELECT and explicit CAST. The aggregate needs the same scale-aware and session-aware temporal formatting path rather than raw internal String() methods.

Regression coverage

After the fix, add focused aggregate-executor tests for scale 0/3/6 and SQL regression coverage for direct vs explicit-cast aggregation at two session time zones. Include ordered and grouped forms so merge/serialization paths cannot reintroduce the raw internal format.

Related

Activity

  1. added this to the MO-202609 milestone on Sep 11, 2026
  2. added
    kind/bug
    on Sep 11, 2026
  3. added theissue type on Sep 11, 2026
  4. Ariznawlll commented on Sep 11, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充影响:时间精度丢失也会使 GROUP_CONCAT(DISTINCT ...) 的输出在文本层面自相矛盾。

    当前 main e7d46d6dfb27696211ca828c55e245d3bd1b634d 上,四个互不相同的 DATETIME(6) 值:

    2024-01-02 03:04:05.100001
    2024-01-02 03:04:05.100002
    2024-01-02 03:04:05.900000
    2024-01-02 03:04:06.000000
    

    执行:

    select count(distinct d),
           group_concat(distinct d order by d separator '|')
    from t;

    MatrixOne 返回:

    4    2024-01-02 03:04:05|2024-01-02 03:04:05|2024-01-02 03:04:05|2024-01-02 03:04:06
    

    DISTINCT 按原始时间值保留了四项,但 GROUP_CONCAT 在输出转换时去掉了微秒,因而结果中出现三个完全相同的文本项。TIME(6) 也有相同行为:原始 distinct count 为 4,输出前三项都变成 03:04:05。

    MySQL 8.3.0 保留声明的六位精度:

    4    2024-01-02 03:04:05.100001|2024-01-02 03:04:05.100002|2024-01-02 03:04:05.900000|2024-01-02 03:04:06.000000
    

    该现象在同一 2-CN 本地分布式环境连续 3 次一致。问题不只是显示差异:下游按分隔符解析 GROUP_CONCAT(DISTINCT temporal) 时,无法恢复或区分已经通过 DISTINCT 的原始值。

  5. Ariznawlll commented on Sep 11, 2026

    @Ariznawlll
    CollaboratorAuthor

    最新 main 065a67528608c475d0219e0be6b7d454a58f7b1a 复核:四个不同的 DATETIME(6)/TIME(6) 值经 GROUP_CONCAT(DISTINCT ... ORDER BY ...) 后,前三项仍被格式化成完全相同的秒级文本;原始 COUNT(DISTINCT) 仍为 4。连续 3 次一致。

  6. assigned and unassigned on Sep 14, 2026
  7. Ariznawlll commented on Sep 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:bb358ea76aeb44a6eed5079616e7e75ba35e75b9
    • 部署方式:macOS arm64 本地 standalone,1 CN / 1 TN / 1 LogService
    • 测试日期:2026-09-14

    原问题验证

    对 DATETIME(6)、TIME(6)、TIMESTAMP(6) 比较 GROUP_CONCAT(value) 与 GROUP_CONCAT(CAST(value AS CHAR))。连续 3 轮三个比较均为 1;微秒没有丢失,也没有暴露内部 UTC 后缀。

    Happy Path 覆盖

    1. DATETIME(6) 和正负 TIME(6) 的 aggregate/cast 文本完全一致。
    2. TIMESTAMP(6) 在 +00:00 下与显式 CAST 一致;切换至 +08:00 后,SQL PREPARE 路径返回按会话时区转换的 2024-01-02 03:04:05.123456|2024-01-02 03:04:06.654321。

    Unhappy Path 覆盖

    该问题没有应拒绝的输入;时间精度、负 TIME 与时区切换均为有效边界,已作为兼容性控制覆盖。测试只读,不修改源数据。

    白盒验证

    test/distributed/cases/function/group_concat_temporal.sql 已存在对应 SQL 回归;实现修复为 matrixone#28701。本轮以公开 SQL 验证格式化与会话时区链路。

    回归测试

    已加入 motr#169:suites/14_issue_regression/t/issue_28579_28593_28595_28653_28657_28669_compatibility.test。定向用例连续 3/3 通过,共 150/150 statements。

    测试证据

    • 本地输出 SHA-256:6817c73d112d012ae784cbb9c0fc9b515a313e4fd1b1057f0abd7ea15125b9f6(3 轮一致)。
    • 回归 PR:motr#169。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions