Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked open and closed issues.
No existing issue was found for Boolean arguments across the mathematical-function family.
Branch Name
main
Commit ID
f0c31cd4b830be32442cf329e0a3fb08aa9c16c3
Other Environment Information
- Local standalone MatrixOne built from the commit above
- Reference: MySQL 8.3.0
Actual Behavior
Most mathematical functions reject a MatrixOne BOOL expression instead of applying MySQL's numeric Boolean conversion (TRUE -> 1, FALSE -> 0). This affects Boolean literals, predicate results, and BOOLEAN columns.
Representative examples:
SELECT SQRT(1=1), SQRT(1=2);
-- MatrixOne: invalid argument function sqrt, bad value [BOOL]
-- MySQL: 1, 0
SELECT LOG(1=1), LOG(1=2);
-- MatrixOne: invalid argument function log, bad value [BOOL]
-- MySQL: 0, NULL
SELECT ROUND(1=1), TRUNCATE(1=2,2);
-- MatrixOne: invalid argument function round, bad value [BOOL]
-- MySQL: 1, 0
SELECT POWER(1=1,2), SIN(1=1);
-- MatrixOne: invalid argument function power, bad value [BOOL BIGINT]
-- MySQL: 1, 0.8414709848078965The complete affected set found in this pass is:
ABS,SQRT,SIGNACOS,ASIN,ATAN,ATAN2,COS,COT,SIN,TANDEGREES,RADIANS,EXPLN, one- and two-argumentLOG,LOG2,LOG10POWER/POW- one- and two-argument
ROUND, andTRUNCATE
SQL PREPARE does not consistently reject the value. Several floating-point functions instead silently evaluate a prepared TRUE as zero:
PREPARE p1 FROM 'SELECT ACOS(?)';
SET @v=TRUE;
EXECUTE p1 USING @v;
-- MatrixOne: 1.5707963267948966 (ACOS(0))
-- MySQL: 0 (ACOS(1))
PREPARE p2 FROM 'SELECT SIN(?)';
SET @v=TRUE;
EXECUTE p2 USING @v;
-- MatrixOne: 0
-- MySQL: 0.8414709848078965The same prepared-value corruption was observed for ACOS, ASIN, ATAN, ATAN2, COS, COT, DEGREES, RADIANS, SIN, and TAN. Other functions either reject the prepared Boolean or happen to produce the correct value, so prepared execution is inconsistent within the family.
Every literal, predicate, column, and prepared form was repeated three times. The session and server remained healthy after each rejected statement.
Expected Behavior
Mathematical functions should apply MySQL-compatible numeric conversion to Boolean expressions. TRUE must be evaluated as 1, FALSE as 0, and NULL must remain NULL, consistently for direct expressions, columns, and prepared parameters.
Steps to Reproduce
DROP DATABASE IF EXISTS codex_math_boolean;
CREATE DATABASE codex_math_boolean;
USE codex_math_boolean;
CREATE TABLE src(id INT PRIMARY KEY, b BOOLEAN);
INSERT INTO src VALUES (1,TRUE),(2,FALSE),(3,NULL);
SELECT SQRT(TRUE), SQRT(FALSE);
SELECT SQRT(1=1), SQRT(1=2);
SELECT id,SQRT(b) FROM src WHERE id=1;
SELECT LOG(TRUE), LOG(FALSE);
SELECT POWER(TRUE,2), ROUND(TRUE), TRUNCATE(FALSE,2);
SELECT SIN(TRUE), ACOS(TRUE), DEGREES(TRUE);
PREPARE p FROM 'SELECT SIN(?)';
SET @v=TRUE;
EXECUTE p USING @v;
DEALLOCATE PREPARE p;Controls
- Integer and ordinary floating/DECIMAL inputs continue to work.
- Numeric-prefix character inputs are accepted by the floating-point functions tested here and agree with MySQL.
CEIL,CEILING,FLOOR, andMODalready accept direct Boolean arguments, demonstrating that Boolean-to-numeric conversion is supported elsewhere in the same function family.NULLwith a supported input type remainsNULL.
Root Cause
Most entries in supportedMathBuiltIns use fixedTypeMatch and register only integer, unsigned integer, floating-point, or DECIMAL overloads. Their overload conversion does not consistently admit BOOL. Prepared markers take a separate conversion path, which explains why some calls are rejected while several floating-point calls execute with TRUE converted to zero.
Activity
fix(function): accept boolean values in math functions (#28513)
Ariznawlll commentedon Sep 10, 2026
测试版本
mainfc621e3616d229c7a29d0c80e73ed8eb1997459c1 Log / 1 TN / 1 CN原问题验证
直接布尔表达式和 BOOLEAN 列路径已正确:
SIN(TRUE)=0.841470984808、ACOS(TRUE)=0,连续 3 次一致。但 SQL
PREPARE/EXECUTE仍稳定复现 3/3:实际为
0 / 0 / 1.570796326795;期望为1 / 0.841470984808 / 0。绑定变量自身SELECT ?返回true,错误发生在预编译参数进入 DOUBLE 数值上下文时。Happy Path 覆盖
SQRT/LOG/POWER/ROUND/TRUNCATE/SIN/ACOS的 TRUE/FALSE 结果符合数值 Bool coercion。SQRT/SIN/LOG对 TRUE/FALSE/NULL 分别返回正确数值和 NULL。Unhappy Path 覆盖
SQRT(-1)和ACOS(2)均返回 NULL;后续表计数仍为 3,服务可继续查询。该路径未发现资源或会话异常。白盒验证
修复 PR matrixone#28513 的
TestMathPreparedMarkersKeepNumericTargetsForBooleanValues等定向 Go 测试可以通过,但其覆盖的是解析期 target type;未端到端执行绑定 BOOL 值,所以未捕获本次执行期TRUE -> 0。回归测试
未加入 MOTR:当前预编译公开 SQL 路径仍返回错误值,不能把错误行为录为回归基线。修复后应补充包含
PREPARE/EXECUTE绑定 TRUE/FALSE 与真实数值断言的自动回归。测试证据
fc621e3616。@XuPeng-SH 请修复后转回,并在 PR/issue 中贴出 SQL
PREPARE/EXECUTE的 TRUE/FALSE 自测结果及执行期数值断言。测试结论
测试不通过。
fix: preserve prepared Boolean math semantics (#28628)
fix: install prepared Boolean precision rewrites (#28651)
Ariznawlll commentedon Sep 11, 2026
最新 main 验收通过,可关闭。\n\n验证版本:
cd8e8d91343798f565f8ad0f8473cb995b8b361b。\n\n覆盖与结果:\n- 直接 Boolean 表达式:SQRT、SIN、ACOS、LOG对TRUE/FALSE返回数值语义(1/0),对NULL返回NULL。\n- Boolean 列:三种值均验证,结果与直接表达式一致。\n- SQL PREPARE 浮点参数:CAST(? AS DOUBLE)、SIN(?)、ACOS(?)分别覆盖TRUE/FALSE/NULL。\n- SQL PREPARE 精度参数:ROUND(1.25, ?)、TRUNCATE(1.25, ?)对TRUE/FALSE/NULL均正确;此前遗漏的TRUE精度参数在修复前服务可稳定复现ERROR 20203: invalid argument cast to int, bad value true,当前 main 已不复现。\n- 新增 MOTR 回归用例已在最新 main 隔离实例连续执行 3/3 通过(共 75 条语句)。\n\n自动化回归已提交:https://github.com/matrixorigin/motr/pull/161\nfix(function): accept boolean values in math functions (matrixorigin#…
fix: preserve prepared Boolean math semantics (matrixorigin#28628)
fix: install prepared Boolean precision rewrites (matrixorigin#28651)
fix(function): accept boolean values in math functions (matrixorigin#…
fix: preserve prepared Boolean math semantics (matrixorigin#28628)
fix: install prepared Boolean precision rewrites (matrixorigin#28651)
fix(function): accept boolean values in math functions (matrixorigin#…
fix: preserve prepared Boolean math semantics (matrixorigin#28628)
fix: install prepared Boolean precision rewrites (matrixorigin#28651)