Repository navigation
Description
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
2after every error succeeds, so the cached statement remains reusable. ROUND(123.456, ?)andTRUNCATE(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
fix: preserve prepared table-function domains through consumers and C…
Ariznawlll commentedon Sep 27, 2026
测试版本
main5be6cd90b501da225be591ffffe6000bf01f515e原问题验证
在上述最新 main 上按 issue 原始复现步骤执行,并独立重复 3 次;3/3 均满足修复后的预期。当前 main 已包含修复提交
5d80e0bc0348c31325c9a54488561c567076abb0。Happy Path 覆盖
Unhappy Path 覆盖
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 次通过。测试证据
5be6cd90b501da225be591ffffe6000bf01f515e测试结论
测试通过。