Skip to content

[Compatibility]: ROUND and TRUNCATE reject dynamic or NULL precision arguments #28492

Closed

Description

@Ariznawlll

Environment

  • MatrixOne: latest main, commit f0c31cd4b830be32442cf329e0a3fb08aa9c16c3
  • MySQL comparison: 8.3.0

Compatibility gap

MatrixOne requires the precision argument of ROUND(X, D) and TRUNCATE(X, D) to be a non-NULL constant. MySQL supports an integer expression evaluated for each row and propagates NULL normally.

Reproduction

CREATE DATABASE dynamic_precision;
USE dynamic_precision;

CREATE TABLE t (
  id INT PRIMARY KEY,
  x DECIMAL(12,4),
  d INT
);

INSERT INTO t VALUES
  (1,123.4567,0),
  (2,123.4567,1),
  (3,123.4567,2),
  (4,123.4567,-1),
  (5,-123.4567,1),
  (6,123.4567,NULL);

SELECT id, ROUND(x,d), TRUNCATE(x,d) FROM t ORDER BY id;

MatrixOne rejects the query with:

invalid argument the second argument of the round, bad value not const

MySQL 8.3 evaluates the precision for each row, for example:

1 | 123.0000  | 123.0000
2 | 123.5000  | 123.4000
3 | 123.4600  | 123.4500
4 | 120.0000  | 120.0000
5 | -123.5000 | -123.4000
6 | NULL      | NULL

Constant NULL is also rejected instead of propagated:

SELECT ROUND(123.4567, NULL), TRUNCATE(123.4567, NULL);

Coverage

The gap was reproduced three times for both ROUND and TRUNCATE, with DECIMAL and DOUBLE values, through:

  • integer precision columns, including zero, positive, negative, and NULL values;
  • arithmetic and CASE expressions;
  • correlated and uncorrelated scalar subqueries;
  • joined precision columns;
  • a view: creation succeeds, but querying the view always fails;
  • CTAS: table creation fails;
  • SQL prepared statements: non-NULL precision parameters work, but a NULL parameter is rejected.

Controls with an ordinary constant integer precision produce the correct value. A derived relation whose precision expression folds to a constant also works, confirming that the restriction is specifically on non-constant/NULL execution vectors. The server remains healthy after all runs.

Code analysis

All numeric overloads route through generalMathMulti in pkg/sql/plan/function/func_binary.go. It rejects both a constant NULL and every non-constant vector before invoking the numeric implementation:

if ivecs[1].IsConstNull() || !ivecs[1].IsConst() {
    return moerr.NewInvalidArg(..., "not const")
}
digits = vector.MustFixedColWithTypeCheck[int64](ivecs[1])[0]

The implementation therefore reads only element zero of D and has no row-wise/null-aware path.

Activity

  1. added this to the MO-202609 milestone on Sep 9, 2026
  2. added theissue type on Sep 9, 2026
  3. added
    severity/s0
    and removed on Sep 9, 2026
  4. assigned and unassigned on Sep 10, 2026
  5. Ariznawlll commented on Sep 10, 2026

    @Ariznawlll
    CollaboratorAuthor

    最新 main ac660ae56ecd37bab3dd8c61193617a323377029 已不再存在本 issue 描述的常量限制。

    已重新覆盖并与 MySQL 8.0.46 对照:

    • ROUND / TRUNCATE 的动态精度列:0、正数、负数、逐行 NULL;
    • DECIMAL 与 DOUBLE 输入;
    • d+0、CASE、相关/非相关标量子查询、JOIN 产生的精度;
    • 常量 NULL;
    • PreparedStatement 的整数、负数、NULL 参数;
    • View 查询与 CTAS 值。

    上述路径均可执行,逐行值与 MySQL 一致;完整矩阵重复 3 次一致。当前实现 generalMathMulti 已将 round / truncate 的非常量或空精度转到逐行 opBinaryFixedFixedToFixed 路径。

    因此按当前 main 验证结果关闭本 issue。

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

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions