Repository navigation
Description
Environment
- MatrixOne: latest
main, commitf0c31cd4b830be32442cf329e0a3fb08aa9c16c3 - 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
fix: support dynamic precision for ROUND and TRUNCATE (#28502)
Ariznawlll commentedon Sep 10, 2026
最新
mainac660ae56ecd37bab3dd8c61193617a323377029已不再存在本 issue 描述的常量限制。已重新覆盖并与 MySQL 8.0.46 对照:
ROUND/TRUNCATE的动态精度列:0、正数、负数、逐行NULL;d+0、CASE、相关/非相关标量子查询、JOIN 产生的精度;NULL;NULL参数;上述路径均可执行,逐行值与 MySQL 一致;完整矩阵重复 3 次一致。当前实现
generalMathMulti已将round/truncate的非常量或空精度转到逐行opBinaryFixedFixedToFixed路径。因此按当前 main 验证结果关闭本 issue。
fix: support dynamic precision for ROUND and TRUNCATE (matrixorigin#2…
fix: support dynamic precision for ROUND and TRUNCATE (matrixorigin#2…
fix: support dynamic precision for ROUND and TRUNCATE (matrixorigin#2…