Skip to content

[Bug]: prepared CEIL and FLOOR reject non-integer runtime precision domains #29314

Closed

Description

@Ariznawlll

Environment

  • MatrixOne main: 95b1d2bfd9d756d08320569858080cb16f230fff
  • Local standalone launch configuration

Problem

CEIL(value, ?) and FLOOR(value, ?) accept an integer runtime parameter in a SQL prepared statement, but reject the same cached statement when the runtime value comes from DECIMAL, DOUBLE, or character numeric domains. Equivalent direct expressions are accepted, and ROUND / TRUNCATE accept the same prepared runtime domains.

This makes the result depend on whether the integer-like precision reaches the function through a prepared parameter. The shared integer-parameter contract added for these functions is expected to coerce the source domain before execution.

Reproduction

SELECT CEIL(123.456,2.5), FLOOR(123.456,2.5);
SELECT CEIL(123.456,2.5e0), FLOOR(123.456,2.5e0);
SELECT CEIL(123.456,'2.5tail'), FLOOR(123.456,'2.5tail');

PREPARE p FROM 'SELECT CEIL(123.456,?), FLOOR(123.456,?)';

SET @d=2;
EXECUTE p USING @d,@d;

SET @d=2.5;
EXECUTE p USING @d,@d;

SET @d=2.5e0;
EXECUTE p USING @d,@d;

SET @d='2.5tail';
EXECUTE p USING @d,@d;

SET @d=2;
EXECUTE p USING @d,@d;

The direct expressions return values, and both executions using integer 2 return:

123.460 | 123.450

Each prepared execution using DECIMAL, DOUBLE, or character numeric runtime values returns:

ERROR 20203 (HY000): invalid argument the second argument of the ceil, bad value not const

The same error also occurs when the parameter is explicitly wrapped in CAST(? AS SIGNED), while the equivalent direct CAST(2.5 AS SIGNED) expression is accepted.

Controls

  • Repeated the complete sequence three times with identical results.
  • Rebinding the original statement to integer 2 after every error succeeds, so the cached statement remains reusable.
  • ROUND(123.456, ?) and TRUNCATE(123.456, ?) accept the DECIMAL, DOUBLE, and character numeric runtime values.
  • A broader prepared execution matrix for the other migrated integer-parameter functions did not reproduce this behavior.

Code path

generalMathMulti in pkg/sql/plan/function/func_binary.go requires the precision vector for CEIL and FLOOR to be a constant INT64. Prepared specialization converts these non-integer source domains to an execution vector that is no longer marked constant, so the function rejects it before reading the converted precision. ROUND and TRUNCATE have a row-wise fallback in the same helper and therefore remain executable.

Regression context

The issue is present after the integer-parameter migration in #29164. That migration explicitly includes CEIL and FLOOR precision parameters and prepared provenance in its scope.

Activity

  1. added this to the MO-202609 milestone on Sep 24, 2026
  2. added
    kind/bug
    on Sep 24, 2026
  3. added theissue type on Sep 24, 2026
  4. self-assigned this
    on Sep 24, 2026
  5. added a commit that references this issue on Sep 24, 2026
    5d80e0b
  6. Ariznawlll commented on Sep 27, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 部署方式:本地单机(1 CN / 1 TN / 1 LogService)
    • 测试日期:2026-09-27

    原问题验证

    在上述最新 main 上按 issue 原始复现步骤执行,并独立重复 3 次;3/3 均满足修复后的预期。当前 main 已包含修复提交 5d80e0bc0348c31325c9a54488561c567076abb0。

    Happy Path 覆盖

    1. prepared CEIL/FLOOR 覆盖整数、DECIMAL、科学计数法及字符串精度参数,值与合入 BVT 契约一致。

    Unhappy Path 覆盖

    1. 精度在 2、2.5、2.5e0、2.5tail 后重新绑定为 2,结果保持可复用。

    白盒验证

    确认修复提交 5d80e0bc0348c31325c9a54488561c567076abb0 是当前 main 的祖先,并核对对应 MatrixOne BVT/实现路径;本次另以公开 SQL 协议执行黑盒验收。

    回归测试

    已加入 MOTR PR #204 的 issue_29311_29313_29314_29320_prepared_domains.test,MOTR 提交 2b4462f2;本地基线比对连续 3 次通过。

    测试证据

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions