Skip to content

[Bug]: conditional expressions lose temporal fractional-second precision #28896

Description

@Ariznawlll

Problem

MatrixOne loses fractional-second precision when temporal values pass through common conditional expressions. The selected value is changed even when every temporal branch has an explicit fractional precision.

The affected paths include COALESCE, IFNULL, IF, searched/simple CASE, prepared parameters, views, and CTAS.

Reproduction

drop database if exists conditional_temporal_precision;
create database conditional_temporal_precision;
use conditional_temporal_precision;

create table src(
  id int primary key,
  d date,
  dt6 datetime(6),
  ts6 timestamp(6) null,
  tm6 time(6)
);
insert into src values
  (1, '2024-02-29', '2024-02-29 12:34:56.123456',
      '2024-02-29 12:34:56.123456', '12:34:56.123456'),
  (2, null, '2024-03-01 01:02:03.999999',
      null, '23:59:59.999999');

create view v as
select id,
       coalesce(tm6, cast('00:00:00.000001' as time(6))) as c_tm6,
       ifnull(dt6, d) as i_dtd,
       if(id = 1, ts6, dt6) as f_tsdt,
       case when id = 1 then ts6 else dt6 end as k_tsdt,
       case id when 1 then ts6 else dt6 end as simple_tsdt
from src;

select * from v order by id;
select column_name, column_type, datetime_precision
from information_schema.columns
where table_schema = database() and table_name = 'v'
order by ordinal_position;

create table ctas as select * from v;
select * from ctas order by id;

Prepared execution is also affected:

prepare p from
  'select coalesce(?,cast(''00:00:00.000001'' as time(6))),
          ifnull(?,cast(''2000-01-01 00:00:00.000001'' as datetime(6))),
          if(1,?,cast(''2000-01-01 00:00:00.000001'' as datetime(6))),
          case when 1 then ? else cast(''2000-01-01 00:00:00.000001'' as datetime(6)) end';
set @tm = cast('12:34:56.123456' as time(6));
set @dt = cast('2024-02-29 12:34:56.123456' as datetime(6));
execute p using @tm, @dt, @dt, @dt;

MatrixOne result

  • COALESCE(TIME(6), TIME(6)) is exposed as TIME(0) and returns 12:34:56.
  • For input 23:59:59.999999, the view returns 23:59:59; CTAS materialization changes that value again to 24:00:00.
  • IFNULL(DATETIME(6), DATE), IF(TIMESTAMP(6), DATETIME(6)), and both CASE forms are exposed as DATETIME(0).
  • 2024-03-01 01:02:03.999999 becomes 2024-03-01 01:02:04 in those expressions.
  • Prepared parameters lose the same six fractional digits.

MySQL 8.0.45 result

The corresponding expressions are TIME(6) or DATETIME(6) and preserve the original values, including .123456 and .999999, in direct selection, views, CTAS, and prepared execution.

Additional metadata inconsistency

COALESCE(TIMESTAMP(6), TIMESTAMP(3)) preserves the value and reports datetime_precision=6 in MatrixOne, but column_type is rendered as TIMESTAMP(0) rather than TIMESTAMP(6).

Scope checked

  • TIME(6) with TIME(3) and constant TIME(6) fallbacks;
  • DATE, DATETIME(3/6), and TIMESTAMP(3/6) combinations;
  • COALESCE, IFNULL, IF, searched CASE, and simple CASE;
  • direct selection, view, CTAS, and prepared statements;
  • ordinary fractions and carry boundary .999999;
  • three independent runs with byte-identical output on each database.

Environment

  • MatrixOne: official main commit 0c3a04f390adaf6281fd592a49778ea5b1155e67
  • MySQL control: 8.0.45
  • Local single-node MatrixOne deployment

Activity

  1. added this to the MO-202609 milestone on Sep 15, 2026
  2. added theissue type on Sep 15, 2026
  3. self-assigned this
    on Sep 15, 2026
  4. Ariznawlll commented on Sep 15, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充 NULLIF 路径(official main 0c3a04f390adaf6281fd592a49778ea5b1155e67,MySQL 8.0.45 对照):

    NULLIF(CAST('2024-02-29 12:34:56.123456' AS DATETIME(6)),
           CAST('2000-01-01 00:00:00.001' AS DATETIME(3)))
    
    NULLIF(CAST('23:59:59.999999' AS TIME(6)),
           CAST('00:00:00.001' AS TIME(3)))

    MatrixOne 将返回类型降为 DATETIME(0) / TIME(0),选中的第一个参数丢失 6 位小数;.999999 还会在 View/CTAS 路径触发秒进位。MySQL 保留第一个参数的微秒值。直接查询、View 和 CTAS 均已覆盖,3 次独立执行结果一致。

    因此受影响条件函数还包括 NULLIF,不仅是原报告中的 COALESCE、IFNULL、IF 和 CASE。

  5. added a commit that references this issue on Sep 17, 2026
    f6f8c0c
  6. Ariznawlll commented on Sep 17, 2026

    @Ariznawlll
    CollaboratorAuthor

    当前 main 复测未通过,转回 @XuPeng-SH 继续处理。

    验证环境:本地单机 MatrixOne,由远端 main 0370bb4d6b118da29e164c54aa34ee010ed897bc 全新构建;PR #28941 merge commit f6f8c0c885f999cbde3b0d394194b0a4a74176ae 已包含。独立执行 3/3,结果一致。

    复现覆盖 COALESCE、IFNULL、IF、searched/simple CASE、View、CTAS 和 prepared 参数。TIME(6) 仍公开为 TIME(0);混合时间条件表达式仍公开为 DATETIME(0)。.123456 被截断,2024-03-01 01:02:03.999999 被舍入为 2024-03-01 01:02:04,而 CTAS 中 23:59:59.999999 进一步变为 24:00:00。prepared 执行同样丢失六位小数。

    期望是在 direct/View/CTAS/prepared 路径保留六位精度及原始值。当前验收未通过,issue 保持 Open。

  7. added 2 commits that reference this issue on Sep 17, 2026
    385154b
    fe9c331
  8. added 2 commits that reference this issue on Sep 19, 2026
    aeee7db
    d8ddce9
  9. slyunnn commented on Sep 23, 2026

    @slyunnn

    Regression and extended verification for #28896 (2026-09-23)

    Verification Environment

    • Verified against local origin/main at 66da3877e9e77f01083c4aac0cb9f94ab6e11fe6, feat(sql): support EXCEPT ALL multiset subtraction (#29228).
    • The running Proxy, CN1, CN2, TN, and Log service containers all used the same locally built image sha256:2f11e09a1d306d186281dd444b465d69ed9ebc674a548c6fabac2c85c714f104, built from that exact clean source worktree.
    • Topology: 1 Log service / 1 TN / 2 CN / 1 Proxy. Connectivity and real DDL/DML execution succeeded through Proxy 6001, CN1 16001, and CN2 16002.
    • The SQL prepared path used server-side PREPARE / EXECUTE. The binary extension used Go database/sql with go-sql-driver/mysql, interpolateParams=false, and actual COM_STMT_PREPARE / COM_STMT_EXECUTE.
    • Initial PR #28941 (f6f8c0c885f999cbde3b0d394194b0a4a74176ae) did not fully close the temporal path; the issue's follow-up verification recorded the remaining failure. The effective follow-up is PR #29075, merge commit aeee7db5099b4347a5c2e5f8d3e4785d76884100, fix: close expression result contract regressions, including acaed0abd4c49ad38339f21437d7df5e3e8839d0, fix: isolate temporal prepared parameter domains, f6bf1ba3c25570787b6632b09c0aaa20a3263f61, fix(frontend): scope temporal execute domains by consumer, and d987cf6354b56aa1eab0e6c016eaf2860f81eb69, fix: fence mixed temporal conditional plans.

    What Was Covered

    • OK — Original COALESCE, IFNULL, IF, searched CASE, and simple CASE reproduction passed on Proxy 6001, CN1 16001, and CN2 16002. TIME(6) and DATETIME(6) values retained .123456 and .999999 rather than truncating or rounding.
    • OK — View and CTAS values and information_schema.columns metadata retained TIME(6) / DATETIME(6) for the affected conditional expressions on all three endpoints; 23:59:59.999999 did not become 24:00:00.
    • OK — NULL/fallback boundary: COALESCE preserved a TIME(6) fallback of 00:00:00.000001; IFNULL(DATETIME(6), DATE) retained DATETIME(6) and rendered a date fallback as 00:00:00.000000.
    • OK — Original SQL PREPARE / EXECUTE parameters retained six fractional digits for COALESCE, IFNULL, IF, and CASE on all three endpoints.
    • OK — Binary prepared extension used Go database/sql + go-sql-driver/mysql with interpolateParams=false; real COM_STMT_PREPARE / COM_STMT_EXECUTE retained TIME(6) and DATETIME(6) fractions on all three endpoints.
    • OK — NULLIF retained the first argument's TIME(6) / DATETIME(6) precision, including .999999; the nearest TIME(0)-first-argument control correctly remained TIME(0).
    • OK — COALESCE(TIMESTAMP(6), TIMESTAMP(3)) returned the six-digit selected value and exposed TIMESTAMP(6) with datetime_precision = 6 in both View and CTAS metadata on all three endpoints.
    • OK — Existing BVT test/distributed/cases/function/func_expression_result_contracts.test was replayed twice through mo-tester via Proxy 6001; each run passed 68/68 statements with 0 failed, ignored, or abnormal results.
    • Not covered — A live MySQL 8.0.45 differential run was not repeated locally. The MatrixOne assertions use the exact expected values and metadata stated in the issue.
    • Not covered — Historical unfixed binaries were not rebuilt for this run; the issue's existing follow-up comment already records the failure on fresh main containing the incomplete PR #28941.

    Findings

    The reported loss of fractional-second precision is no longer reproducible on current main. Conditional temporal expressions preserve both their runtime value and result-domain metadata through direct selection, View, CTAS, SQL prepared execution, and binary prepared execution.

    The three endpoint protocol cases ran in parallel with separate databases (issue28896_ts_proxy, issue28896_ts_cn1, and issue28896_ts_cn2), so they had no shared catalog objects. The two mo-tester replays were intentionally serial because they use one self-cleaning BVT fixture and result comparison on the same instance.

    Large-data regression is not needed. This is a scalar planner/frontend type-and-scale propagation defect that is fully observable with one-row expressions plus the small 3-row NULL/fallback fixture. It does not depend on row-count thresholds, block/batch boundaries, memory, spill, concurrency, skew, network transfer, or resource scale.

    MOTR / BVT Coverage

    No MOTR branch, commit, or new test was needed. Current main already contains the dedicated expression-contract BVT from PR #29075, including conditional temporal View/CTAS metadata and values, plus NULLIF precision controls. It was replayed twice successfully; no test source was modified during this verification.

    Final Conclusion

    Fixed. The original conditional temporal precision failure and the covered SQL/binary prepared, View, CTAS, NULLIF, NULL-fallback, and mixed-TIMESTAMP metadata variants pass on Proxy 6001, CN1 16001, and CN2 16002 using the current main runtime. Large-data regression is not required for the reasons above.

  10. Ariznawlll commented on Sep 23, 2026

    @Ariznawlll
    CollaboratorAuthor

    最新 main 验证通过,关闭。

    验证版本:16d8e5106caaedfe0a7296e4f628683e1b6a92b4,包含 PR #29075。

    覆盖:

    现有产品 BVT func_expression_result_contracts.test 继续覆盖更完整的条件表达式结果契约。

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