Skip to content

[Bug]: inconsistent fractional-second precision for TIME/DATETIME/TIMESTAMP across storage, casts, and functions #22701

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main,3.0

Commit ID

latest

Other Environment Information

- Hardware parameters:
- OS type:
- Others:

Actual Behavior

Values were stored at full microsecond precision while declared precision (scale) was only applied at display, causing mismatches in storage, comparisons, and query results.
CAST between TIME/DATETIME/TIMESTAMP did not consistently round/truncate to target scale; some paths preserved full precision.
Built-ins (NOW/CURRENT_TIMESTAMP/SYSDATE) didn’t consistently honor requested precision; default NOW() behavior caused test flakiness.
String-to-datetime casts were forced to scale=6 via type inference even when the target type had lower scale, producing incorrect equality and grouping behavior.
TIMEDIFF precision didn’t align with MySQL (result precision should equal the max input precision).
Tests that assumed pre-fix behavior (e.g., TIMESTAMP(0) retaining microseconds) broke or were flaky.

Expected Behavior

Declared fractional-second precision is enforced end-to-end: on storage, in CAST/conversion, and in function outputs.
Rounding uses round-half-up (e.g., .5 rounds up).
String literals are parsed with scale=6, then truncated/rounded when assigned/cast to a lower-scale target (MySQL 8.0 compatible).
TIMEDIFF result precision equals the highest precision of its arguments.
NOW()/CURRENT_TIMESTAMP/SYSDATE respect explicit scales; default NOW() behaves as TIMESTAMP(0).
Equality/grouping/comparisons are deterministic and consistent with the declared scales.

Steps to Reproduce

https://github.com/matrixorigin/MO-Cloud/issues/5761

Additional information

No response

Activity

  1. added this to the MO-202510 milestone on Oct 29, 2025
  2. self-assigned this
    on Oct 29, 2025
  3. added theissue type on Oct 29, 2025
  4. added
    kind/bug
    severity/s0
    on Oct 29, 2025
  5. changed the title [-][Bug]: incorrectly applies precision truncation only to display layer while storing full precision on Datetime[/-] [+][Bug]: inconsistent fractional-second precision for TIME/DATETIME/TIMESTAMP across storage, casts, and functions[/+] on Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions