Skip to content

[Compatibility]: most math functions reject or misread Boolean expressions #28484

Closed

Description

@Ariznawlll

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.8414709848078965

The complete affected set found in this pass is:

  • ABS, SQRT, SIGN
  • ACOS, ASIN, ATAN, ATAN2, COS, COT, SIN, TAN
  • DEGREES, RADIANS, EXP
  • LN, one- and two-argument LOG, LOG2, LOG10
  • POWER/POW
  • one- and two-argument ROUND, and TRUNCATE

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.8414709848078965

The 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, and MOD already accept direct Boolean arguments, demonstrating that Boolean-to-numeric conversion is supported elsewhere in the same function family.
  • NULL with a supported input type remains NULL.

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

  1. added this to the MO-202609 milestone on Sep 9, 2026
  2. added theissue type on Sep 9, 2026
  3. self-assigned this
    on Sep 9, 2026
  4. added a commit that references this issue on Sep 10, 2026
    f6aa238
  5. Ariznawlll commented on Sep 10, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:fc621e3616d229c7a29d0c80e73ed8eb1997459c
    • 部署方式:本地单机 1 Log / 1 TN / 1 CN
    • 测试日期:2026-09-10

    原问题验证

    直接布尔表达式和 BOOLEAN 列路径已正确:SIN(TRUE)=0.841470984808、ACOS(TRUE)=0,连续 3 次一致。

    但 SQL PREPARE/EXECUTE 仍稳定复现 3/3:

    PREPARE p FROM 'SELECT CAST(? AS DOUBLE), ROUND(SIN(?),12), ROUND(ACOS(?),12)';
    SET @b = TRUE;
    EXECUTE p USING @b, @b, @b;

    实际为 0 / 0 / 1.570796326795;期望为 1 / 0.841470984808 / 0。绑定变量自身 SELECT ? 返回 true,错误发生在预编译参数进入 DOUBLE 数值上下文时。

    Happy Path 覆盖

    1. 直接 SQRT/LOG/POWER/ROUND/TRUNCATE/SIN/ACOS 的 TRUE/FALSE 结果符合数值 Bool coercion。
    2. BOOLEAN 列的 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 与真实数值断言的自动回归。

    测试证据

    • 本地构建二进制的 Git commit 为 fc621e3616。
    • 问题对应修复 PR:matrixone#28513。

    @XuPeng-SH 请修复后转回,并在 PR/issue 中贴出 SQL PREPARE/EXECUTE 的 TRUE/FALSE 自测结果及执行期数值断言。

    测试结论

    测试不通过。

  6. added 2 commits that reference this issue on Sep 11, 2026
    a6a493a
    cd8e8d9
  7. Ariznawlll commented on Sep 11, 2026

    @Ariznawlll
    CollaboratorAuthor

    最新 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\n

  8. added 9 commits that reference this issue on Sep 17, 2026
    3770fc3
    d7f8edc
    bc49b61
    8dd4975
    c693be1
    2ed7d08
    4e6fa23
    c68be31
    141bf9c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions