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]: CTAS truncates fractional seconds from FROM_UNIXTIME #28124
CTAS truncates fractional seconds produced by FROM_UNIXTIME. The source epoch value has six fractional digits and direct evaluation returns DATETIME(6)-equivalent data, but the CTAS target is created as unscaled DATETIME and stores only whole seconds.
Environment
MatrixOne official main: 99ed717b769e261b842c2f17345bd65865fc1470
Clean local single-CN build and isolated data directory
Reproduced identically in 3/3 runs
Reproduction
CREATETABLEsrc (id INTPRIMARY KEY, ts TIMESTAMP(6) NOT NULL);
INSERT INTO src VALUES (1, '2024-03-10 06:30:00.123456');
SELECT UNIX_TIMESTAMP(ts), FROM_UNIXTIME(UNIX_TIMESTAMP(ts)) FROM src;
-- 1710052200.123456 | 2024-03-10 06:30:00.123456CREATETABLEctas_from_unixASSELECT FROM_UNIXTIME(UNIX_TIMESTAMP(ts)) AS v FROM src;
SHOW CREATE TABLE ctas_from_unix;
SELECT v FROM ctas_from_unix;
Actual result:
CREATE TABLE `ctas_from_unix` (`v` datetime NOT NULL)
2024-03-10 06:30:00
Scope control
CREATE TABLE ... AS SELECT UNIX_TIMESTAMP(ts) creates DECIMAL(38,6) and stores 1710052200.123456 correctly. A view over FROM_UNIXTIME(UNIX_TIMESTAMP(ts)) also returns 2024-03-10 06:30:00.123456. The loss is therefore specific to CTAS schema derivation for fractional FROM_UNIXTIME results.
Expected behavior
CTAS should create a temporal target with sufficient fractional scale and retain .123456, rather than silently coercing the result to whole seconds.
Preliminary code observation
The FROM_UNIXTIME evaluator has separate decimal/float paths that construct a datetime with nanoseconds, but the corresponding static overload return metadata is unscaled DATETIME. CTAS derives its output schema from that metadata and the insert then truncates the fractional component. This is a diagnosis hypothesis, not a proposed fix.
Suggested regression coverage
Cover CTAS for decimal and float fractional epochs, a UNIX_TIMESTAMP(timestamp(6)) round trip, and a view/direct-query control that preserves microseconds.
执行 go test -vet=off ./pkg/sql/plan -run 'TestCreateTableAsSelectPreservesUnixTimePrecision|TestCreateTableAsSelectWithTemporalFractionalSeconds' -count=1,通过。
Activity
fix temporal precision, prepared binding, and boundary semantics (#28316
jiangxinmeng1 commentedon Sep 14, 2026
fixed by #28316
Ariznawlll commentedon Sep 14, 2026
测试版本
mainbe30a70fe50eac4e8c78e5117fdd69179ba853e0mo-service,独立数据目录原问题验证
以
TIMESTAMP(6) '2024-03-10 06:30:00.123456'作为源表数据执行CREATE TABLE ... AS SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(ts))。连续 3 次创建出的目标列均为DATETIME(6),查询值为2024-03-10 06:30:00.123456,不再落为整秒。Happy Path 覆盖
UNIX_TIMESTAMP(ts)/FROM_UNIXTIME(...)往返保留123456微秒。COLUMN_TYPE=DATETIME(6)、DATETIME_PRECISION=6,与实际值一致。Unhappy Path 覆盖
不适用:此 issue 的风险是合法时间值在 CTAS 中被静默截断,并非非法输入拒绝。已用声明类型、物化值和微秒提取三项断言防止静默精度丢失。
白盒验证
执行
go test -vet=off ./pkg/sql/plan -run 'TestCreateTableAsSelectPreservesUnixTimePrecision|TestCreateTableAsSelectWithTemporalFractionalSeconds' -count=1,通过。回归测试
issue_28121_28123_28124_28122_28144_temporal_ctas.test./motr --repeat 3 14_issue_regression.issue_28121_28123_28124_28122_28144_temporal_ctas:3/3 通过,66/66 statements。测试证据
定向结果与预期基线见 MOTR PR #170。该 case 在
14_issue_regression套件实跑中为 22/22 statements 通过;套件内其他既有 case 的失败未修改。测试结论
测试通过。
fix temporal precision, prepared binding, and boundary semantics (mat…
fix temporal precision, prepared binding, and boundary semantics (mat…
fix temporal precision, prepared binding, and boundary semantics (mat…