Skip to content

[Bug]: CTAS persists fractional TIME values in an unscaled TIME column #28127

Closed as not planned

Description

@Ariznawlll

Summary

CTAS can persist fractional seconds in a column declared as unscaled TIME. This violates the declared FSP contract: direct INSERT ... SELECT into the same TIME/TIME(0) target truncates the fraction, while CTAS stores it.

Environment

  • MatrixOne official main: 99ed717b769e261b842c2f17345bd65865fc1470
  • Clean local single-CN build and isolated data directory
  • Reproduced identically in 3/3 runs

Reproduction

CREATE TABLE src (id INT PRIMARY KEY, dt DATETIME(6) NOT NULL);
INSERT INTO src VALUES (1, '2024-01-01 07:08:09.123456');

CREATE TABLE ctas_time AS
SELECT TIME(dt) AS v FROM src;
SHOW CREATE TABLE ctas_time;
SELECT v FROM ctas_time;

Actual result:

CREATE TABLE `ctas_time` (`v` time NOT NULL)
07:08:09.123456

Scope control

The normal target-insert path respects the same FSP contract:

CREATE TABLE t0 (v TIME NOT NULL);
CREATE TABLE t6 (v TIME(6) NOT NULL);
INSERT INTO t0 SELECT TIME(dt) FROM src;
INSERT INTO t6 SELECT TIME(dt) FROM src;
SELECT v FROM t0; -- 07:08:09
SELECT v FROM t6; -- 07:08:09.123456

Likewise, direct literal INSERT into TIME/TIME(0) rounds to whole seconds. The unexpected behavior is the CTAS path retaining precision that its own synthesized schema does not declare.

Expected behavior

CTAS must either declare TIME(6) for this expression or coerce the inserted value to the declared unscaled TIME precision. Schema metadata and persisted value must agree.

Preliminary code observation

The TIME() evaluator returns a value carrying source fractional precision at runtime, while CTAS derives an unscaled TIME target schema from static metadata. Its generated insert appears not to apply the same target-scale coercion as normal INSERT ... SELECT. This is a diagnosis hypothesis, not a proposed fix.

Suggested regression coverage

Compare CTAS and INSERT ... SELECT into TIME, TIME(0), and TIME(6) for a TIME(DATETIME(6)) expression; assert both column metadata and stored values.

Activity

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

    @XuPeng-SH
    Contributor

    Tracking consolidated into #24436. The canonical issue includes this report's independent scope and acceptance criteria. This is administrative consolidation, not a claim that the defect is fixed. The original reproduction and discussion remain preserved here.

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