Skip to content

[Compatibility]: explicit_defaults_for_timestamp is accepted but ignored by TIMESTAMP DDL #28598

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues, including open and closed issues.

Branch Name

main

Commit ID

fc621e3

Other Environment Information

  • MatrixOne: locally built from the commit above (8.0.30-MatrixOne-v1.3.0)
  • MySQL baseline: 8.0.46
  • Verification date: 2026-09-10

Actual Behavior

MatrixOne exposes explicit_defaults_for_timestamp as a writable dynamic session/global variable, but setting it to OFF has no effect on TIMESTAMP column definition or write behavior.

With the setting ON, MatrixOne and MySQL both create an unconstrained TIMESTAMP column as nullable with a NULL default:

SET SESSION explicit_defaults_for_timestamp=ON;
CREATE TABLE t(id INT PRIMARY KEY, ts TIMESTAMP);
ts TIMESTAMP NULL DEFAULT NULL

With the setting OFF, MySQL 8.0.46 applies its documented legacy implicit-first-TIMESTAMP behavior:

ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

MatrixOne still creates:

ts TIMESTAMP NULL DEFAULT NULL

The schema difference changes stored values:

  • Omitting ts inserts the current timestamp in MySQL but NULL in MatrixOne.
  • Explicitly inserting NULL into the implicit first TIMESTAMP stores the current timestamp in MySQL but NULL in MatrixOne.
  • TIMESTAMP NOT NULL with no explicit default gains DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP under MySQL OFF, so an omitted value succeeds; MatrixOne keeps no default and rejects the same insert with invalid default value for column 'ts'.
  • An explicitly nullable TIMESTAMP NULL remains nullable in both engines, which is the expected control.

SELECT @@session.explicit_defaults_for_timestamp correctly reports 0 after the MatrixOne assignment, so the variable is stored but ignored by DDL binding.

Expected Behavior

When MatrixOne accepts explicit_defaults_for_timestamp=OFF, TIMESTAMP DDL and implicit write behavior should follow MySQL's corresponding compatibility rules. If the legacy mode is intentionally unsupported, the setting should not be exposed as a writable dynamic variable that silently has no effect.

Steps to Reproduce

DROP DATABASE IF EXISTS explicit_timestamp_defaults;
CREATE DATABASE explicit_timestamp_defaults;
USE explicit_timestamp_defaults;

SET SESSION explicit_defaults_for_timestamp=OFF;
SELECT @@session.explicit_defaults_for_timestamp;

CREATE TABLE plain_t(
  id INT PRIMARY KEY,
  ts TIMESTAMP
);
SHOW CREATE TABLE plain_t;

INSERT INTO plain_t(id) VALUES(1);
INSERT INTO plain_t VALUES(2,NULL);
SELECT id,ts,ts IS NULL FROM plain_t ORDER BY id;

CREATE TABLE nullable_t(
  id INT PRIMARY KEY,
  ts TIMESTAMP NULL
);
SHOW CREATE TABLE nullable_t;

CREATE TABLE notnull_t(
  id INT PRIMARY KEY,
  ts TIMESTAMP NOT NULL
);
SHOW CREATE TABLE notnull_t;
INSERT INTO notnull_t(id) VALUES(1);

Additional information

pkg/frontend/variables.go registers explicit_defaults_for_timestamp as a dynamic ScopeBoth Boolean with default 1. No production parser, binder, default-expression, or timestamp-column path reads the setting; the only other source occurrence is an error-message definition describing the MySQL option.

ON/OFF, unconstrained/explicit NULL/explicit NOT NULL column definitions, SHOW CREATE, omitted values, explicit NULL values, and post-create updates were reproduced three times on the same latest-main build and compared with MySQL 8.0.46. No existing issue for this variable was found.

Activity

  1. added this to the MO-202609 milestone on Sep 10, 2026
  2. added theissue type on Sep 10, 2026
  3. XuPeng-SH commented on Sep 10, 2026

    @XuPeng-SH
    Contributor

    Triage routing: assigned to @jiangxinmeng1. Labels normalized to kind/bug + needs-triage (existing compatibility labels, when present, are retained).

    Recommended PR decomposition:

    • PR-T7 — TIMESTAMP defaults/current-time behavior (#28598 + #28599): align explicit_defaults_for_timestamp, automatic TIMESTAMP columns, and session timestamp override. They share TIMESTAMP default-value generation and need DDL plus INSERT/UPDATE coverage.
    • Keep #28570 separate because DST gap mapping is a time-zone conversion contract, not default generation.

    Suggested priority: P2; confirm exact MySQL mode/version compatibility before changing DDL behavior.

  4. jiangxinmeng1 commented on Oct 22, 2026

    @jiangxinmeng1
    Contributor

    已在 main 提交 c232b6d2a1b5a94ac624c4954586569841c1e153 复核。合并的 #28932 已让 explicit_defaults_for_timestamp=OFF 参与 TIMESTAMP DDL、默认值及显式 NULL 写入处理;相关远程回归测试 TestTableDumpTimestampDefaults、TestLegacyTimestampRuntimeNullAssignment 通过。

    请 @Ariznawlll 按本 issue 的 SQL 步骤复核,若仍有差异请补充具体结果。

  5. Ariznawlll commented on Oct 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main
    • commit:cca94b810ce87a38d1af16d7b418ea727eeda81c(包含已合入修复 fix remaining date/time compatibility issues #28932 的 merge commit)
    • 部署方式:本地隔离工作树,1 LOG / 1 TN / 2 CN;通过 CN0 的真实 MySQL TCP 黑盒测试
    • 测试日期:2026-10-22

    原问题验证

    explicit_defaults_for_timestamp=OFF 后首个隐式 TIMESTAMP 的 SHOW CREATE 为 NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP();省略值和显式 NULL 插入后 2 行均非 NULL。 独立启动环境重复 3/3 轮通过,未用开发者自测代替 QA。

    Happy Path 覆盖

    1. 显式 TIMESTAMP NULL 可保留 NULL,显式 NOT NULL 省略值成功;更新普通列并等待 1 秒后 ts>旧值 为 1;恢复 ON 时普通 TIMESTAMP 为可空。
    2. 新增成对 SQL 回归定向重复 3/3 通过,结果与独立 Go 黑盒断言核对。

    Unhappy Path 覆盖

    1. OFF 下插入显式 NULL 不再错误存 NULL,ON 下未被错误套用遗留首列规则;本轮未验证 global 变量传播。
    2. 每轮在独立临时数据库执行并 DROP 清理;失败场景无残留表数据或错误 golden。

    白盒验证

    本轮未单独跑 Go UT / race;本问题为确定性 SQL 值或类型路径,以真实协议黑盒及 SQL 回归验收。完整 MatrixOne suite 未执行。

    回归测试

    • MOTR 汇总 PR #247,本项所在 t 用例 及同名 r 预期结果;定向 --repeat 3 通过。PR 当前仍 Open,尚未声称已合并或 CI 全绿。
    • 未运行完整 MOTR suite、TKE/集成 CI;不据此声称其他发布线通过。

    测试证据

    上述 PR 的成对 t/r、实际 main SHA,以及本地 go test ./pkg/tests/issues -run '^TestQATemporalScreenshot20261022$' -count=3 与 MOTR 定向 --repeat 3 均通过;黑盒临时测试仅用于本次独立验收,未作为持久产品代码提交。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions