Skip to content

[Compatibility]: prepared FROM_UNIXTIME with integer input reports DATETIME(6) instead of DATETIME #30192

Closed

Description

@Ariznawlll

Description

FROM_UNIXTIME(?) keeps fractional-seconds precision 6 for a prepared integer epoch parameter. MySQL 8.0.46 returns precision 0 for the same integer parameter. The epoch value is correct on both engines; the difference is the prepared result/CTAS column type and its metadata.

Environment

  • MatrixOne main ancestor commit: 2ce4e58af6f03b943ee288ffad81012766cf830a (local two-CN cluster behind Proxy)
  • Current origin/main at investigation: 944b721d1b3705cdb51d1e26f1a04611a08c8401; the relevant FROM_UNIXTIME return-type and prepared-plan source files are unchanged from the tested commit
  • MySQL: 8.0.46
  • Session time zone: +00:00
  • Date: 2026-10-14

Steps to reproduce

CREATE DATABASE probe_db;
USE probe_db;
SET SESSION time_zone = '+00:00';
SET @epoch = 1704067200;

PREPARE p FROM
  'CREATE TABLE ctas_int AS SELECT FROM_UNIXTIME(?) AS ts';
EXECUTE p USING @epoch;

SELECT COLUMN_TYPE, DATETIME_PRECISION
FROM information_schema.columns
WHERE table_schema = 'probe_db'
  AND table_name = 'ctas_int'
  AND column_name = 'ts';

Actual behavior

MatrixOne reports datetime(6), precision 6; the same prepared CTAS reports datetime, precision 0 on MySQL. A prepared SELECT FROM_UNIXTIME(?) also prints .000000 in MatrixOne for the integer parameter, while MySQL prints no fractional part.

The prepared CTAS schema mismatch reproduced in 3/3 fresh tables on each engine.

Expected behavior

For an integer epoch input, the result type should have fractional-seconds precision 0, as in MySQL 8.0.46.

Stability and controls

  • Prepared integer epoch: MatrixOne DATETIME(6) vs MySQL DATETIME, 3/3.
  • Literal FROM_UNIXTIME(1704067200) CTAS: both report DATETIME, precision 0.
  • User-variable FROM_UNIXTIME(@epoch) CTAS with @epoch = 1704067200: both report DATETIME, precision 0.
  • Prepared decimal parameter 1704067200.123456: both report DATETIME(6), precision 6, and retain .123456.
  • The materialized epoch value is otherwise correct; this is a precision/type metadata mismatch, not loss of the integer timestamp value.

Code analysis

The result type is selected by fromUnixTimeReturnType in pkg/sql/plan/function/list_builtIn.go from the statically resolved argument type. A prepared marker is resolved with fractional precision 6, so the return type remains DATETIME(6) when execution binds an integer. The prepared-plan coverage in pkg/sql/plan/prepared_interval_test.go also preserves the marker under FROM_UNIXTIME(?); execution does not narrow the return precision to the bound integer type.

Regression coverage

After a fix, cover prepared integer and decimal epoch parameters through both SELECT metadata and CTAS information_schema.columns, with literal and user-variable controls.

Related

Activity

  1. added this to the MO-202610 milestone on Oct 14, 2026
  2. added theissue type on Oct 14, 2026
  3. added
    ai-easy
    on Oct 19, 2026
  4. slyunnn commented on Oct 21, 2026

    @slyunnn

    Verification update (2026-10-21)

    Verified on latest origin/main e47f45ca6548e198e73ecb242521047bfd449850 (fix(python-sdk): redact create_table diagnostics and gate the success log (#30678)). The fresh runtime topology was 2 CN / 1 TN / 1 LogService / Proxy; Proxy 6001, CN1 16001, and CN2 16002 each accepted MySQL connections. Session time zone was +00:00.

    • On MatrixOne, the exact SQL PREPARE/EXECUTE CTAS reproduction returned DATETIME, precision 0 for the integer parameter through Proxy, CN1, and CN2 (three fresh tables per direct CN). Decimal 1704067200.123456 returned DATETIME(6), precision 6; literal and user-variable controls returned DATETIME, precision 0.
    • The same cases were checked with a Go MySQL driver using binary COM_STMT_PREPARE/EXECUTE: MatrixOne returned precision 0 for the integer parameter and 6 for the decimal parameter.
    • Against local MySQL 8.0.46, the exact SQL PREPARE/EXECUTE integer CTAS returned DATETIME(6), precision 6 in 3/3 fresh tables; binary COM_STMT also returned DATETIME(6). Literal and user-variable controls returned precision 0.

    The current MatrixOne result matches the expected behavior explicitly stated in this issue (integer prepared input should produce precision 0), so the reported MatrixOne mismatch is not reproducible on latest main. Related PR #30224, merged as d82e828b0a4df9ce635fe573c1e90c5cde978bf9, states that the FROM_UNIXTIME reproduction already passed on its base and made no FROM_UNIXTIME kernel change.

    @Ariznawlll, could you please confirm whether the MySQL 8.0.46 result in the issue was obtained with the exact SQL PREPARE/EXECUTE steps above? My local run of those steps returned precision 6, opposite to the issue report's precision 0. If possible, please share the exact command/output (and any relevant client/session details) so we can reconcile the MySQL baseline. This is a request to verify the reported comparison, not to clarify the expected behavior, which is already explicit in the issue.

    The related existing BVT is test/distributed/cases/function/func_temporal_consistency_28851.test; the full BVT harness was not rerun. No large-data regression is relevant to this result-type metadata case.

  5. slyunnn commented on Oct 21, 2026

    @slyunnn

    Compatibility baseline correction and engineering follow-up (2026-10-21)

    The issue creator has confirmed that the MySQL 8.0.46 result for the exact SQL PREPARE/EXECUTE integer-parameter case matches the independent verification: CTAS metadata is DATETIME(6), precision 6. The original issue's MySQL expectation of precision 0 appears to have used the ordinary integer-literal/user-variable result as the prepared-statement baseline; those are different cases.

    On latest MatrixOne origin/main e47f45ca6548e198e73ecb242521047bfd449850, the same SQL PREPARE/EXECUTE CTAS returned DATETIME, precision 0 through Proxy, CN1, and CN2. Thus the original reported direction (MatrixOne 6 vs MySQL 0) is not accurate, but the corrected comparison currently points to the opposite result (MatrixOne 0 vs MySQL 6).

    Reopening this issue for engineering review of the intended prepared-result compatibility contract and whether the latest MatrixOne precision-0 result is intentional. Related merged PR #30224 (d82e828b0a4df9ce635fe573c1e90c5cde978bf9) includes this issue and says the original FROM_UNIXTIME reproduction already passed on its base without a kernel change.

    The issue is assigned to iamlinjunhong, author of PR #30224, for review. No new issue is being created pending this assessment.

  6. XuPeng-SH commented on Nov 1, 2026

    @XuPeng-SH
    Contributor

    转 QA 验证。修复 #31141 已合入 main,merge SHA:950ef51d97422022e84386cfb85006288b791e62。

    本轮核对了合并状态、修复范围及本 issue 全部评论:按已纠正的 MySQL 8.0.46 基线,直接 prepared FROM_UNIXTIME 参数应暴露 DATETIME(6),包括整数和 decimal3;普通字面量、用户变量和显式 CAST 保持各自精度契约。旧 main 精度 0 的反例由本次新修复覆盖,未见适用于合并后版本的已验证反例或尚未完成的开发 follow-up。

    证据及限制:PR 作者报告在 ef81e86 上 plan/function 全量及 focused frontend/parser 测试通过,真实服务 prepared_temporal_results.sql 208/208 和 interval_operator_string_operand.sql 31/31 均通过两次;PR 合并队列记录 CI Required 成功。以上为远端记录/作者报告,本轮未运行本地测试,也未独立重建原始测试证据;不表示本轮验收通过。作者明确未新增 MySQL differential、race 或 multi-CN 验证。

    请 QA 在包含上述 merge SHA 的版本上,按纠正后的基线对比 SQL PREPARE/EXECUTE 与 binary COM_STMT 的 SELECT 元数据、CTAS information_schema 和实际值:整数、decimal3/6、NULL、负值及普通/显式 CAST 控制;关注重复执行时参数切换、CTAS 写入精度与 SELECT 句柄历史隔离。按原报告匹配时区及 sql_mode,补充 Proxy/直连 CN 路径。issue 保持 open,待报告者复核。

  7. Ariznawlll commented on Nov 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。按 issue 后续修正的比较基线,prepared 整数参数的 FROM_UNIXTIME 结果元数据为 DATETIME(6)。

    关键证据

    • 官方 main@d61a7206c16b30baa4efc525eb6067c4364035aa;隔离 MO、MySQL 8.0.45,UTC。
    • **Happy case:**SQL PREPARE/EXECUTE CTAS 的整数及六位小数 epoch 均得到 datetime(6)、精度 6 和正确值,两端三轮一致。二进制 COM_STMT 对整数及同一预编译句柄重用的类型、精度和结果在两 CN 各三轮通过。
    • **Unhappy case:**NULL 参数返回 NULL,随后同一二进制句柄重新执行整数参数仍正确。主库 prepared 时间结果 BVT 经旧测试器结果格式转换后每轮 208/208,三轮通过;该 BVT 使用值比较,实际协议元数据由独立二进制检查覆盖。
    • 白盒:prepared temporal result、marker reuse 与 FROM_UNIXTIME Go 定向测试运行三轮。二进制回归加入 MOTR #305。

    待解决点

    MOTR PR 尚待评审合入;原 issue 的 MySQL 预期已由后续评论纠正,本轮对照为 8.0.45 而非原记录的 8.0.46。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easyarea/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions