Skip to content

[Compatibility]: TIME_TRUNCATE_FRACTIONAL is accepted but temporal conversions still round #28600

Closed

Description

@Ariznawlll

Environment

  • MatrixOne: main at fc621e3616d229c7a29d0c80e73ed8eb1997459c
  • MySQL reference: 8.0.46
  • Session time zone: +00:00

Problem

MatrixOne accepts TIME_TRUNCATE_FRACTIONAL in sql_mode, but temporal values are still rounded when converted to a lower fractional-seconds precision. The mode therefore has no effect on TIME, DATETIME, or TIMESTAMP values.

MySQL documents this mode as selecting truncation instead of rounding when temporal values are converted to lower precision: TIME_TRUNCATE_FRACTIONAL.

Minimal reproduction

SET SESSION time_zone = '+00:00';
SET SESSION sql_mode = 'STRICT_TRANS_TABLES,TIME_TRUNCATE_FRACTIONAL';

CREATE TABLE t(
  id INT PRIMARY KEY,
  dt DATETIME(3),
  ts TIMESTAMP(3),
  tm TIME(3)
);

INSERT INTO t VALUES(
  1,
  '2024-01-02 03:04:05.123556',
  '2024-01-02 03:04:05.123556',
  '12:34:56.123556'
);

SELECT CAST(dt AS CHAR), CAST(ts AS CHAR), CAST(tm AS CHAR) FROM t;

MatrixOne returns rounded values:

2024-01-02 03:04:05.124
2024-01-02 03:04:05.124
12:34:56.124

MySQL 8.0.46 returns truncated values:

2024-01-02 03:04:05.123
2024-01-02 03:04:05.123
12:34:56.123

Without TIME_TRUNCATE_FRACTIONAL, both systems round the same input to .124.

Boundary behavior

With the mode enabled, MatrixOne also rounds 23:59:59.999500 across the day boundary and rounds 12:59:59.999500 across the hour boundary:

DATETIME/TIMESTAMP: 2024-01-03 00:00:00.000
TIME:               13:00:00.000

MySQL truncates them to 2024-01-02 23:59:59.999 and 12:59:59.999. Negative TIME values show the same difference: MatrixOne converts -12:34:56.123556 to -12:34:56.124, while MySQL converts it to -12:34:56.123.

Affected execution paths

The same mode-insensitive rounding occurs in MatrixOne for:

  • direct INSERT and UPDATE;
  • non-key assignments in INSERT ... ON DUPLICATE KEY UPDATE;
  • INSERT ... SELECT from FSP 6 columns into FSP 3 columns;
  • SQL PREPARE ... EXECUTE ... USING parameters;
  • explicit CAST(... AS DATETIME(3)) and CAST(... AS TIME(3));
  • CTAS over those casts;
  • ALTER TABLE ... MODIFY from FSP 6 columns to FSP 3 columns.

A prepared statement created once and executed first with ordinary rounding mode and then with TIME_TRUNCATE_FRACTIONAL returns .124 both times in MatrixOne. MySQL returns .124 for the first execution and .123 for the second, so the mode is evaluated for the active execution rather than being permanently captured by preparation.

Code analysis

pkg/frontend/variables.go lists TIME_TRUNCATE_FRACTIONAL as a valid sql_mode token, but there is no other reference to this token in the repository. pkg/container/types/timestamp.go:getMsec unconditionally examines the first discarded digit and increments the retained fractional part when it is 5-9. TIME, DATETIME, TIMESTAMP, and relevant casts use this helper without a session-mode input, so truncation cannot currently be selected.

The behavior above was reproduced three times with fresh databases and connections. All listed paths include an ordinary rounding-mode control, where MatrixOne and MySQL agree.

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-T8 — fractional temporal conversion (#28600 only): implement TIME_TRUNCATE_FRACTIONAL at the conversion/rounding owner. Keep it separate from invalid-date validation and DST handling because the rounding and validation contracts differ.

    Suggested priority: P2; cover exact precision boundaries and all affected temporal conversions.

  4. jiangxinmeng1 commented on Oct 21, 2026

    @jiangxinmeng1
    Contributor

    fixed by #28932

  5. slyunnn commented on Oct 23, 2026

    @slyunnn

    Regression and extended verification for #28600 (2026-10-23)

    Verification Environment

    • Latest origin/main: 2b388dd1690f83e2e807d6809180336dae2a68eb — fix(sql): honor cancellation inside LoopJoin and LIKE evaluation (#30862). The running MatrixOne binary was built from this commit with Go 1.27.1.
    • Topology: 2 CN / 1 TN / 1 LogService / Proxy.
    • Proxy 6831, CN1 16131, and CN2 16132 were each reachable and tested directly.
    • Client: MySQL CLI over the MySQL client protocol. Prepared coverage used server-side PREPARE/EXECUTE. Reference: MySQL 8.0.46; session time zone was +00:00.

    What Was Covered

    • OK — Original DATETIME(3), TIMESTAMP(3), and TIME(3) insert under STRICT_TRANS_TABLES,TIME_TRUNCATE_FRACTIONAL: input fraction .123556 is truncated to .123 on all three MatrixOne endpoints, matching MySQL.
    • OK — Ordinary-mode control without TIME_TRUNCATE_FRACTIONAL rounds the same .123556 input to .124, matching MySQL.
    • OK — Boundary and sign cases: 23:59:59.999500 truncates without carrying into the next day; 12:59:59.999500 stays within the hour; negative TIME -12:34:56.123556 truncates to -12:34:56.123. All match MySQL.
    • OK — The same prepared statement was executed in round/truncate/round mode order; results were .124, .123, .124 on each system, confirming the active execution mode is observed.
    • OK — INSERT ... SELECT from FSP 6 into FSP 3, UPDATE, non-key assignments in INSERT ... ON DUPLICATE KEY UPDATE, explicit CAST, CTAS over casts, and ALTER TABLE ... MODIFY all truncate to FSP 3 and match MySQL on Proxy, CN1, and CN2.
    • OK — Unhappy-path INSERT IGNORE with malformed TIME input retains 12:34:56 and warning code 1265 on all endpoints and MySQL.
    • Not covered — Full distributed BVT/TKE was not rerun on this latest main; the targeted SQL cases above were executed directly against the built service.

    Findings

    The fix is merged in PR #28932, merge commit 0c3f7e035d90fbcf205b3164c560eda2df38335e, titled fix remaining date/time compatibility issues. It applies TIME_TRUNCATE_FRACTIONAL at temporal conversion/rounding paths while preserving ordinary-mode rounding and evaluating session mode for the active prepared execution.

    The malformed-input control has different warning message wording (MatrixOne: Data truncated for TIME value; MySQL: Data truncated for column 'v' at row 1), while the warning code and stored value match. This diagnostic-text difference does not change the verified truncation behavior and is not treated as an unresolved runtime failure for this issue.

    MOTR / BVT Coverage

    The existing product distributed regression is test/distributed/cases/function/temporal_assignment_regression.sql; it covers truncation mode, casts, and prepared-statement mode changes. No additional MOTR case or commit was needed. The full BVT harness was not run locally, so no latest-main full-suite pass is claimed.

    Large-data regression is not needed: fractional temporal conversion is independent of row count and resource scale.

    Final Conclusion

    Fixed — the reported mode-insensitive rounding is fixed on latest main and the original and extended SQL paths tested here match MySQL 8.0.46 through Proxy, CN1, and CN2. The issue remains open for maintainer/reporter workflow; no issue state change was made.

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