Skip to content

[Bug]: temporal-expression CTAS columns retain microseconds but report DATETIME(0) #28236

Description

@Ariznawlll

Summary

CTAS columns derived from fractional temporal expressions can retain microseconds while exposing themselves as DATETIME(0). SHOW CREATE TABLE, information_schema.columns.COLUMN_TYPE, DATETIME_PRECISION, result formatting, and accepted insert precision no longer describe one coherent column type.

This affects expressions whose static result type already carries scale 6, including ADDTIME, SUBTIME, GREATEST, and LEAST; it is distinct from the unscaled static return type already tracked for DATE_ADD / DATE_SUB in #28122.

Environment

  • MatrixOne official main: e7bb0572235ec4bac81eb098eb0ad8900f0065ab
  • Clean local single-CN build and isolated data directory
  • MySQL 8.3 comparison instance
  • Reproduced identically in 3/3 reads

Reproduction

CREATE DATABASE ctas_fsp_meta;
USE ctas_fsp_meta;

CREATE TABLE src (
  id INT PRIMARY KEY,
  dt DATETIME(6),
  d DATE
);
INSERT INTO src VALUES
  (1, '2024-01-01 01:02:03.123456', '2024-01-01'),
  (2, '2024-01-02 02:03:04.654321', '2024-01-02');

CREATE TABLE c_addtime AS
SELECT ADDTIME(dt, '00:00:00.000001') AS v FROM src;

SHOW CREATE TABLE c_addtime;

SELECT DATA_TYPE, COLUMN_TYPE, DATETIME_PRECISION
FROM information_schema.columns
WHERE table_schema = 'ctas_fsp_meta'
  AND table_name = 'c_addtime'
  AND column_name = 'v';

SELECT v, MICROSECOND(v), DATE_FORMAT(v, '%f') FROM c_addtime ORDER BY v;

INSERT INTO c_addtime VALUES ('2031-07-08 09:10:11.654321');
SELECT v, MICROSECOND(v), DATE_FORMAT(v, '%f')
FROM c_addtime WHERE v >= '2031-01-01';

Actual behavior

SHOW CREATE TABLE:
  `v` datetime DEFAULT NULL

information_schema.columns:
  DATA_TYPE = datetime
  COLUMN_TYPE = DATETIME(0)
  DATETIME_PRECISION = 6

CTAS values:
  2024-01-01 01:02:03.123457 | 123457 | 123457
  2024-01-02 02:03:04.654322 | 654322 | 654322

Subsequent insert:
  2031-07-08 09:10:11.654321 | 654321 | 654321

The column stores and returns six fractional digits, but both the persisted DDL and COLUMN_TYPE identify it as DATETIME(0). DATETIME_PRECISION independently reports 6.

The same metadata contradiction occurs with:

CREATE TABLE c_subtime AS
SELECT SUBTIME(dt, '00:00:00.000001') AS v FROM src;

CREATE TABLE c_greatest AS
SELECT GREATEST(dt, d) AS v FROM src;

CREATE TABLE c_least AS
SELECT LEAST(dt, d) AS v FROM src;

Plain-column CTAS, explicit CAST(dt AS DATETIME(6)), and COALESCE(dt, CAST(NULL AS DATETIME(6))) preserve DATETIME(6) consistently, so this is not a general CTAS formatting limitation.

MySQL 8.3 declares all four target columns as DATETIME(6) and reports COLUMN_TYPE=datetime(6), DATETIME_PRECISION=6.

Expected behavior

The persisted CTAS schema and all metadata surfaces should describe the actual six-digit temporal precision:

SHOW CREATE TABLE: datetime(6)
COLUMN_TYPE: datetime(6)
DATETIME_PRECISION: 6

Clients should not receive a DATETIME(0) column descriptor for values that contain fractional seconds.

Code observation

The affected function return-type paths construct a DATETIME carrying scale 6, and the runtime result vectors also retain that scale. The inconsistency appears while the function result type is converted into the persisted CTAS column definition and later rendered through DDL / information schema metadata.

Activity

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

    @Ariznawlll
    CollaboratorAuthor

    补充:CONVERT_TZ() + 字符串字面量的 CTAS 精度元数据

    在 MatrixOne 本地 runtime 8.0.30-MatrixOne-v1.3.0(source commit 2ce4e58af6f03b943ee288ffad81012766cf830a)与隔离 MySQL 8.0.45 对照,三次新建 CTAS 结果一致:

    CREATE TABLE c_tz AS
    SELECT CONVERT_TZ('2024-02-29 23:59:59.123456', '+00:00', '+05:30') AS v;
    引擎 COLUMN_TYPE DATETIME_PRECISION IS_NULLABLE 读取显示 MICROSECOND(v) / DATE_FORMAT(v,'%f')
    MySQL datetime(6) 6 YES 2024-03-01 05:29:59.123456 123456 / 123456
    MO datetime(26) 0 NO 2024-03-01 05:29:59 123456 / 123456

    显式 CAST(... AS DATETIME(6)) 的控制在两端均生成 datetime(6),并显示 .123456。所以当前证据表明微秒值仍保留,差异在 CTAS/结果精度元数据及其显示,不是已证实的存储值截断;属于本 issue 跟踪的 temporal-expression CTAS 精度问题,不另开重复 issue。

  5. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    CONVERT_TZ() 的 DST 与直接结果精度复核

    在隔离 MySQL 8.0.45 实例加载本机时区表后,对比 America/Los_Angeles 春季跳时、秋季重叠时以及固定偏移转换。转换值与 MICROSECOND() 结果均一致:

    Input MySQL 8.0.45 MatrixOne 8.0.30-MatrixOne-v1.3.0
    2024-03-10 01:59:59.999999 LA -> UTC 2024-03-10 09:59:59.999999, µs 999999 显示 2024-03-10 09:59:59, µs 999999
    2024-03-10 02:30:00.123456 LA -> UTC (DST gap) 2024-03-10 10:00:00.123456, µs 123456 显示 2024-03-10 10:00:00, µs 123456
    2024-11-03 01:30:00.123456 LA -> UTC (ambiguous local time) 2024-11-03 08:30:00.123456, µs 123456 显示 2024-11-03 08:30:00, µs 123456
    2024-01-01 00:00:00.123456 +00:00 -> +05:30 2024-01-01 05:30:00.123456, µs 123456 显示 2024-01-01 05:30:00, µs 123456

    因此本轮没有发现 DST 转换值错误;当前观察是直接标量结果的格式/精度暴露不同,微秒值本身保留,属于本 issue 的 temporal-expression 精度元数据范围,不另开 issue。No/SuchZone 在两端均返回 NULL。

  6. jiangxinmeng1 commented on Oct 22, 2026

    @jiangxinmeng1
    Contributor

    已在远程机器 [email protected] 对 clean main(a949c88af0ed)运行 SQL 复现,此 issue 仍未修复:ADDTIME 的 DATETIME(6) CTAS 列报告 datetime,CONVERT_TZ 带 6 位小数的 CTAS 列报告 datetime(26),均应为 datetime(6)。已将本批时间精度问题集中提交到 PR #30798;PR 尚未合入,按要求未验证 PR 分支。转给 Ariznawlll 跟进。

  7. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    PR #30798 adds a dotted-date precision regression (head 529584181e9d89b2b83e0871f846e30d1185634a)

    The formal review found that datetimeLiteralScale scans digits after the last dot, while MatrixOne accepts dotted date separators. Thus:

    CREATE TABLE tz_fsp AS
    SELECT CONVERT_TZ('2024.01.15', '+00:00', '+00:00') AS d;

    is parsed as a valid date-only literal, but the new precision inference counts the day 15 as two fractional digits and assigns Scale/Width=2. CTAS can therefore report DATETIME(2) / DATETIME_PRECISION=2, unlike the equivalent 2024-01-15 input (precision 0). The exact-head source confirms the helper scans from the final .; the repository date tests include 2024.01.15 as a valid dotted date.

    Please infer FSP from the parsed time component rather than punctuation and add controls for dotted date-only and dotted datetime literals without fractions. This extends the existing CTAS precision issue; no duplicate issue opened.

    The finding is from source tracing in the submitted review. I have not independently run the SQL/UT because this environment has no Go runtime. Review: #30798 (review).

  8. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    Follow-up to my existing #30798 finding: aptend's inline review on the exact head 529584181e9d89b2b83e0871f846e30d1185634a now reports independent execution through both BuildPlan and the SQL frontend. It confirms CONVERT_TZ('2024.01.15', ...) and the valid dotted datetime 2024.01.15 12:34:56 produce width/scale 2 despite having no fractional seconds; the dashed-date and true fractional-second controls behave correctly. This strengthens the existing dotted-separator finding; it is reviewer-reported execution, not a local run by me. The issue remains assigned to Ariznawlll and open pending a fix and verification.

  9. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    PR #30798 temporal CTAS precision follow-up (2026-10-22)

    The dotted-date precision finding from the earlier review is reported fixed in PR #30798. The subsequent approval on head 106541b35681a66dc861ac6b349e90c01433b84d reports focused planner coverage and SQL/catalog verification, including dotted date-only and dotted datetime inputs, genuine fractional-second controls, and prepared CTAS. These are the reviewer's recorded results, not a test run performed by me.

    The PR has since synchronized with main; its current head is 29ae828ce55f15b6f218653868a8fa69ecab3491. That head has no commit statuses, and the only associated workflow currently visible is Iceberg Connector E2E, which does not cover the temporal CTAS change. The fix therefore remains pending merge and current-head CI confirmation. Keeping this issue open and assigned to @Ariznawlll.

  10. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    Current-head check (2026-10-22)

    PR #30798 remains open. Its current head is 425e67250c595c05b80a771fa6cbf514dfb95994 (base e7ea085fff9baac1031548b7eddc5e719e6aa782).

    For this exact head, GitHub reports no commit status checks. The only associated workflow run is Iceberg Connector E2E: its adapter-module tidy job passed, while the Iceberg E2E job was skipped; neither exercises planner temporal-CTAS precision. Earlier reviewer-reported SQL/planner verification was on 106541b35681a66dc861ac6b349e90c01433b84d, so it does not validate this updated head.

    I could not run the focused tests here because the available workspace has no MatrixOne git checkout. This issue remains open and assigned to @Ariznawlll pending relevant current-head CI and focused planner/SQL verification.

  11. added a commit that references this issue on Oct 22, 2026
    fe4a265
  12. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    PR #30798 merge update (2026-10-22)

    PR #30798 merged to main at merge commit fe4a265b0d7ab635de80bcef8a69a8beee8ef50b; the merged PR head was 425e67250c595c05b80a771fa6cbf514dfb95994.

    The approval and focused planner/SQL verification recorded earlier in the PR discussion were on 106541b35681a66dc861ac6b349e90c01433b84d, before the final sync with main. Those reviewer-reported results are not a test run performed by me. The final merge commit currently has no commit statuses or associated workflow runs, and I could not run the tests locally because this workspace has no MatrixOne checkout.

    Keeping #28236 open and assigned to @Ariznawlll pending verification on the merged main build; no issue state or assignee change.

  13. Ariznawlll commented on Oct 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main;日期:2026-10-22 UTC(本地执行跨北京时间10月22/23日)。
    • 实际完整 SHA:cf48adddcda41c2ae754904af76b034a83b83163。执行前获取官方 main,结束复核未变。构建 vcs.revision 相同、vcs.modified=false;实际服务 git_version=cf48adddcd。
    • 已逐条阅读 issue 开发评论及修复范围,确认 PR fix(plan): preserve temporal fractional precision in CTAS metadata #30798 MERGED,merge commit fe4a265b0d7ab635de80bcef8a69a8beee8ef50b 在上述 main 祖先链。此次不是复用研发旧 head 的通过结论。
    • 本机隔离 macOS arm64,1 CN / 1 TN / 1 LogService,DISK-V2;独占非默认端口、独立数据库。ARCHSIMD=0;native 输入相对既有构建未变,复用匹配 native 产物。未使用共享 TKE/128/129。复用专用 TN 的 checkpoint scan/flush/incremental=1h 配置,本场景不依赖这些触发间隔。

    原问题验证

    原表 src(id INT PRIMARY KEY, dt DATETIME(6), d DATE),原两行微秒值123456/654321;按原式分别 CTAS ADDTIME、SUBTIME、GREATEST、LEAST,并核对 SHOW CREATE TABLE、information_schema 的 DATA_TYPE/COLUMN_TYPE/DATETIME_PRECISION、文本协议结果字段 type/FSP,以及实际值。

    完整扩展矩阵本地3/3通过;最终独立 MOTR runner 再重复3次,total=3 / success=3 / failed=0 / skipped=0,2.83s,每轮21次 CTAS 元数据/值检查。四个原表达式均为 datetime(6)、precision=6、wire type=12/FSP=6,不再出现元数据0/26与微秒值矛盾。

    Happy Path 覆盖

    1. ADDTIME 两行实际为 2024-01-01 01:02:03.123457、2024-01-02 02:03:04.654322;SUBTIME 为 .123455/.654320,完整日期时间逐值比较。
    2. GREATEST 保留原两行 datetime;LEAST 返回对应两日零点,仍正确声明 datetime(6)。普通列、CAST、COALESCE 三个控制同样保持类型/值一致。
    3. 对上述7张表再插入 2031-07-08 09:10:11.654321,值、MICROSECOND=654321、DATE_FORMAT('%f')='654321' 全部一致。
    4. dotted date-only 和 dotted datetime 无小数:COLUMN_TYPE 为标准 datetime、precision=0、wire FSP=0;不是错误的datetime(2)。真正 .123 为datetime(3),compact .123456 为datetime(6),值均不丢失。
    5. 2024-02-29 23:59:59.123456 从UTC转+05:30,实际 2024-03-01 05:29:59.123456,三层元数据均为6位。
    6. 按本issue此前MySQL参考结果复验LA时区:跳时前 09:59:59.999999、跳时内 10:00:00.123456、秋季重叠 08:30:00.123456(对应原评论日期),值及CTAS精度一致。本轮未重新启动MySQL对照实例。
    7. SQL PREPARE/EXECUTE 的 CTAS 重复使用,将参数由1微秒改为2微秒后结果相应变化,重建目标仍是datetime(6);随后DEALLOCATE。
    8. NULL源行 CTAS 保留NULL;空输入 CTAS 返回空集;两者仍保留datetime(6)及正确wire元数据。

    Unhappy Path 覆盖

    1. 无效时区 No/SuchZone 返回NULL,声明及wire精度仍为datetime(6),没有错误复用旧值。
    2. CTAS不存在的源列返回1054;验证未生成rejected目标表,src原两行三列逐项未改变。
    3. 向CTAS表插入2032年微秒记录后ROLLBACK,该记录count=0。
    4. 每轮删除自己的数据库并验证不存在,关闭连接;任务自有服务退出码0。检查服务日志未发现panic/fatal error/DATA RACE模式;不据此声称全面泄漏审计。
    5. 首次测试脚本把零精度COLUMN_TYPE预期写成必须带(0),而标准返回是datetime。修正为精确datetime,仍严格校验precision=0和wire FSP=0;6/3位和原0/26矛盾的断言未放宽。这是测试预期问题,不是产品失败。

    白盒验证

    同一SHA运行已有测试:go test -p 2 -count=3 -run '^(TestBindConvertTZLiteralFractionalPrecision|TestBuildCTASTemporalFractionalPrecision|TestBuildCTASConvertTZDottedDatePrecision)$' ./pkg/sql/plan,通过,1.306s。仅三个定向测试,不是整个planner包或race;本次顺序类型推导验收未新增MO测试/PR。

    回归测试

    新增独立 MOTR PR #261,head 133b39352e7d7d3bb335d983ce07939fcf8aebb2,基于官方MOTR main 13a6aad987e93be1883daa54f08a63d4cc5fe5a2。当前OPEN/draft;未加入#247,未声称已合入。

    固定版本场景 含正常SQL/文本结果字段检查、确定性out、文档及三个oracle反例测试;后者会拒绝原DATETIME(0)/DATETIME(26)矛盾、错误DDL、wire丢精度和dotted误判。完整MOTR离线框架431项通过,28.643s;不是431项在线产品测试。

    CI run 39810136118 四个job都是零步骤,注释确认Actions预算阻止启动,不能计为CI通过或产品失败。未跑完整MOTR产品suite、整个14_issue_regression产品suite、完整集成CI、Linux/TKE、二进制COM_STMT_EXECUTE、修复前二进制;没有相应通过声明。

    测试证据

    本地 /tmp/mo-28236-qa-mO6CFv/:build.log、probe-final.log、motr-final.log、ut.log、motr-offline.log、motr-service.log,及以上固定版本回归代码。日志没有冒充已上传artifact。结论只针对所列main SHA的本issue及已执行覆盖,不代表4.2发布线或完整CI。

    测试结论

    测试通过。

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