You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Prepared CTAS with TIMESTAMPADD(MICROSECOND) persists the wrong timestamp #30195
A prepared CTAS using TIMESTAMPADD(MICROSECOND, 1, ?) succeeds in MatrixOne but persists a different timestamp: the bound time-of-day and the interval increment are both lost. The same prepared expression returns the correct value when selected directly or used by INSERT ... SELECT; adding an explicit CAST(? AS DATETIME(6)) also makes the CTAS result correct. MySQL 8.0.46 persists the correct value without the cast.
This is a persisted-value correctness issue, distinct from #28562 (CTAS with a source-column TIMESTAMPADD fails during generated SQL reparsing) and from closed #27379 (microsecond result scale on ordinary temporal inputs).
Reproduction
CREATEDATABASErepro;
USE repro;
SET @d ='2024-01-31 12:34:56.000001';
PREPARE p FROM'CREATE TABLE c AS SELECT TIMESTAMPADD(MICROSECOND, 1, ?) AS v';
EXECUTE p USING @d;
SELECT v, CAST(v ASCHAR) FROM c;
MatrixOne stores 2024-01-31 00:00:00.000001.
MySQL 8.0.46 stores 2024-01-31 12:34:56.000002.
The MatrixOne behavior repeated with three input timestamps (including a leap-day value and a 23:59:59.999999 rollover case). Controls on the same MatrixOne commit:
PREPARE ... SELECT TIMESTAMPADD(MICROSECOND, 1, ?) returns the correct timestamp.
PREPARE ... INSERT INTO target SELECT TIMESTAMPADD(MICROSECOND, 1, ?) stores the correct timestamp.
Prepared CTAS with TIMESTAMPADD(MICROSECOND, 1, CAST(? AS DATETIME(6))) stores the correct timestamp.
Environment
MatrixOne: local main-derived commit 2ce4e58af6f03b943ee288ffad81012766cf830a, server reports 8.0.30-MatrixOne-v1.3.0
MySQL: 8.0.46
SQL-level server-side PREPARE / EXECUTE; temporary databases removed after comparison.
MatrixOne 原有 test/distributed/cases/prepare/prepared_temporal_results.sql 也覆盖此路径;本轮未运行该 BVT。MOTR 全 659 case suite 曾启动但因资源范围过大中断,遗留专用库已核对并清理;完整 suite/集成 CI 未完成。
Activity
Ariznawlll commentedon Oct 14, 2026
补充参数日期部分的区间对照,输入均为
2024-01-31 12:34:56.123456:TIMESTAMPADD(HOUR, 1, ?):MatrixOne CTAS 写入2024-01-31 01:00:00;MySQL 写入2024-01-31 13:34:56.123456。TIMESTAMPADD(DAY, 1, ?):MatrixOne CTAS 写入2024-02-01 00:00:00;MySQL 写入2024-02-01 12:34:56.123456。这与正文的
MICROSECOND用例一致:原始参数在 prepared CTAS 路径中没有按完整 datetime 保留。Ariznawlll commentedon Oct 14, 2026
补充双 marker 用例:
@n=1, @d='2024-01-31 12:34:56.123456'时,标量 preparedSELECT TIMESTAMPADD(DAY, ?, ?)在 MatrixOne 返回2024-02-01 12:34:56,MySQL 返回2024-02-01 12:34:56.123456;同一表达式放入 prepared CTAS 后,MatrixOne 仅写入2024-02-01,MySQL 仍写入完整 datetime。说明 interval marker 与 datetime marker 同时出现时也会走到该 CTAS 数据差异。Ariznawlll commentedon Oct 19, 2026
测试版本
main8e63625c4e9baeb1d28c1095c07732f056c04895d82e828b0a4df9ce635fe573c1e90c5cde978bf9经 GitHub compare 确认为上述 main 的祖先。原问题验证
原始 SQL
PREPARE ... CREATE TABLE c AS SELECT TIMESTAMPADD(MICROSECOND,1,?)/EXECUTE USING @d独立运行 3/3:输入2024-01-31 12:34:56.000001,持久化实际值2024-01-31 12:34:56.000002,列类型datetime(6)、精度 6;不再出现旧错值2024-01-31 00:00:00.000001。闰日末尾输入2024-02-29 23:59:59.999999时 3/3 持久化为2024-03-01 00:00:00.000000。Happy Path 覆盖
TIMESTAMPADD(DAY,?,?):3/3 为2024-02-01 12:34:56.123456;HOURCTAS:3/3 为2024-01-31 13:34:56.123456。时间和小数秒未丢失。2024-01-31 12:34:56.123457;INSERT 目标仅 1 行。Unhappy Path 覆盖
invalid与NULL参数,各 3/3 得到 SQL NULL;随后同一 prepare 再执行有效参数,3/3 恢复为正确值。目标库清理后不存在;本缺陷不是失败注入/事务回滚问题。白盒验证
同 SHA 的
pkg/sql/plan与pkg/sql/plan/function定向TestPreparedTemporalResultContracts|TestPreparedTemporalMarkerReuse|TestTemporalCompatibilityExecutionMatrix|TestDynamicTimeResultTypedCalendarAndMask,-count=3PASS;含 prepared SELECT/CTAS 的类型与求值断言。回归测试
t/issue_30195_30196_30197_prepared_temporal.test与对应r/*.result,覆盖三项 issue 的公开 SQL。独立核对期望值后定向重复 3/3,135/135 语句成功、0 skip;PR head623ac129a7d011ae0d441cd4275d0100e5d8d854,尚未合入。test/distributed/cases/prepare/prepared_temporal_results.sql也覆盖此路径;本轮未运行该 BVT。MOTR 全 659 case suite 曾启动但因资源范围过大中断,遗留专用库已核对并清理;完整 suite/集成 CI 未完成。测试证据
total=3 success=3 failed=0 skipped=0 | stmts=135 ok=135 fail=0。测试结论
测试通过。