Skip to content

[Compatibility]: ROUND, CEIL, and FLOOR derive incompatible DECIMAL result types #28595

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues, including open and closed issues.

Branch Name

main

Commit ID

fc621e3

Other Environment Information

  • MatrixOne: locally built from the commit above (8.0.30-MatrixOne-v1.3.0)
  • MySQL baseline: 8.0.46
  • Verification date: 2026-09-10

Actual Behavior

ROUND, CEIL, and FLOOR compute the same significant numeric values as MySQL for exact DECIMAL input, but MatrixOne derives different result precision/type metadata. CTAS persists those incompatible types.

MatrixOne reduces the scale where applicable but always retains the input DECIMAL width. MySQL derives the width required for the integer digits, requested result scale, and possible rounding carry; for smaller DECIMAL input, CEIL and FLOOR return BIGINT.

Examples from CREATE TABLE dst AS SELECT ...:

expression                         MatrixOne CTAS type  MySQL 8.0.46 CTAS type
ROUND(DECIMAL(10,4),2)             DECIMAL(10,2)       DECIMAL(9,2)
ROUND(DECIMAL(10,4),0)             DECIMAL(10,0)       DECIMAL(7,0)
ROUND(DECIMAL(38,10),5)            DECIMAL(38,5)       DECIMAL(34,5)
ROUND(DECIMAL(50,10),5)            DECIMAL(50,5)       DECIMAL(46,5)
CEIL(DECIMAL(10,4))                DECIMAL(10,0)       BIGINT
FLOOR(DECIMAL(10,4))               DECIMAL(10,0)       BIGINT
CEIL(DECIMAL(50,10))               DECIMAL(50,0)       DECIMAL(41,0)
FLOOR(DECIMAL(50,10))              DECIMAL(50,0)       DECIMAL(41,0)

The differences affect result-set/JDBC metadata and schema-generating operations. They can also inflate storage and change downstream implicit casts even though a direct textual display of the significant digits looks correct.

MOD was checked in the same matrix and its DECIMAL precision/scale agrees with MySQL, which isolates the issue to the rounding-family return-type rules.

Expected Behavior

MatrixOne should derive MySQL-compatible exact-numeric result types for ROUND, CEIL, and FLOOR, preserving enough integer capacity and any carry digit without retaining unused fractional capacity in the precision. CTAS, views, and client metadata should expose those derived types.

Steps to Reproduce

DROP DATABASE IF EXISTS decimal_rounding_metadata;
CREATE DATABASE decimal_rounding_metadata;
USE decimal_rounding_metadata;

CREATE TABLE src(
  d64 DECIMAL(10,4),
  d128 DECIMAL(38,10),
  d256 DECIMAL(50,10)
);
INSERT INTO src VALUES(
  12345.6789,
  1234567890123456789012345678.1234567890,
  1234567890123456789012345678901234567890.1234567890
);

CREATE TABLE dst AS SELECT
  ROUND(d64,2) AS round2,
  ROUND(d64,0) AS round0,
  ROUND(d128,5) AS round128,
  ROUND(d256,5) AS round256,
  CEIL(d64) AS ceil64,
  FLOOR(d64) AS floor64,
  CEIL(d256) AS ceil256,
  FLOOR(d256) AS floor256
FROM src;

SHOW CREATE TABLE dst;
SELECT column_name,column_type,numeric_precision,numeric_scale
FROM information_schema.columns
WHERE table_schema=DATABASE() AND table_name='dst'
ORDER BY ordinal_position;

Additional information

The DECIMAL overload return functions for ROUND, CEIL, and FLOOR in pkg/sql/plan/function/list_builtIn.go return parameters[0] unchanged. Constant precision handling later adjusts scale for evaluation, but width remains the source width rather than a function-specific derived precision.

Decimal64/128/256, positive and negative values, requested precision zero/below/above input scale, direct SELECT, CTAS, and information-schema metadata were reproduced three times on the same latest-main build. Existing ROUND issues concern integer value errors and dynamic precision acceptance, not exact-DECIMAL result width/type metadata.

Activity

  1. added this to the MO-202609 milestone on Sep 10, 2026
  2. added theissue type on Sep 10, 2026
  3. daviszhen commented on Sep 10, 2026

    @daviszhen
    Contributor

    A fix is available in #28625.

    Local Docker-isolated verification confirms MySQL-compatible ROUND, CEIL, and FLOOR CTAS metadata. The issue matrix now produces DECIMAL(9,2), DECIMAL(7,0), DECIMAL(34,5), DECIMAL(46,5), BIGINT for small-decimal CEIL/FLOOR, and DECIMAL(41,0) for Decimal256 CEIL/FLOOR. Plan and function package tests pass.

  4. Ariznawlll commented on Sep 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:bb358ea76aeb44a6eed5079616e7e75ba35e75b9
    • 部署方式:macOS arm64 本地 standalone,1 CN / 1 TN / 1 LogService
    • 测试日期:2026-09-14

    原问题验证

    对 DECIMAL(10,4)、DECIMAL(38,10)、DECIMAL(50,10) 执行 ROUND、CEIL、FLOOR 后 CTAS,并读取 information_schema。连续 3 轮结果稳定为 DECIMAL(9,2)、DECIMAL(7,0)、DECIMAL(7,0)、DECIMAL(34,5)、DECIMAL(41,0)。

    Happy Path 覆盖

    1. 覆盖 ROUND 的 Decimal64/128 与指定 scale。
    2. 覆盖 CEIL/FLOOR 的整数结果 metadata,以及 Decimal256 的 carry capacity。
    3. 通过 CTAS 与 information_schema 验证客户端可见的持久化类型,而非仅验证数值。

    Unhappy Path 覆盖

    该问题的接口参数均为有效 exact DECIMAL;未引入不属于本 issue 的动态/NULL precision 语义。CTAS 成功后只读 metadata,未发生部分写入或 schema 异常。

    白盒验证

    修复 PR matrixone#28625 已合入当前 main;本轮以实际 planner/CTAS 公开路径验证返回类型推导。

    回归测试

    已加入 motr#169:suites/14_issue_regression/t/issue_28579_28593_28595_28653_28657_28669_compatibility.test。定向用例连续 3/3 通过,共 150/150 statements。

    测试证据

    • 本地输出 SHA-256:6817c73d112d012ae784cbb9c0fc9b515a313e4fd1b1057f0abd7ea15125b9f6(3 轮一致)。
    • 回归 PR:motr#169。

    测试结论

    测试通过。

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