Skip to content

[Compatibility]: POWER, EXP overflow and COT domain errors abort queries instead of returning NULL #28137

Closed

Description

@Ariznawlll

现象

在 MatrixOne main 99ed717b769e261b842c2f17345bd65865fc1470,部分数值函数对定义域外或溢出输入抛出错误,而不是返回 NULL:

SELECT POWER(-1, 0.5); -- data out of range ... pow(-1,0.5)
SELECT POWER(0, -1);   -- data out of range ... pow(0,-1)
SELECT EXP(1000);      -- data out of range ... exp(1000)
SELECT COT(0);         -- data out of range ... cot(0)

相同实例中,下列同类非法定义域输入返回 NULL:SQRT(-1)、LN(0)、LOG10(-1)、LOG2(0)、ACOS(2)、ASIN(2)、1/0、MOD(1,0)。

期望

为保持 MySQL 兼容性,POWER/EXP/COT 在结果不可表示或数学定义域无效时应返回 NULL(并可产生 warning),不应将整条查询提升为错误。

影响

分析查询、报表或 ETL 中遇到边界数据时,单行非法值会使整个语句失败,无法按 MySQL 的 NULL 传播逻辑继续处理。

复现信息

  • MatrixOne main: 99ed717b769e261b842c2f17345bd65865fc1470
  • 每个语句重复执行 3 次,行为一致

Activity

  1. added this to the MO-202609 milestone on Sep 4, 2026
  2. added
    kind/bug
    on Sep 4, 2026
  3. added theissue type on Sep 4, 2026
  4. assigned and unassigned on Sep 4, 2026
  5. assigned and unassigned on Sep 4, 2026
  6. added a commit that references this issue on Sep 7, 2026
    7fbb401
  7. 6 remaining items

  8. assigned and unassigned on Sep 8, 2026
  9. added a commit that references this issue on Sep 8, 2026
    80d214b
  10. assigned and unassigned on Sep 8, 2026
  11. Lundomn commented on Sep 8, 2026

    @Lundomn
    Contributor

    转 QA 测试:PR #28375 -> Issue #28137

    请重点验证以下 Issue 要求及 PR #28375 的变更:

    1. POWER(-1,0.5)、POWER(0,-1)、EXP(1000)、COT(0) 在当前 main 返回 NULL,不再使整条语句失败。
    2. 混合有效/无效行时,异常行返回 NULL,后续有效行继续计算;覆盖向量、常量/向量、向量/常量、NULL 输入、selection mask(含全掩码)。
    3. 验证 POWER/POW、EXP、COT 的可空元数据和规划行为,包括 IS NULL、CTAS、NOT NULL 源列。
    4. 验证 SUM/COUNT、过滤、INSERT SELECT、UPDATE、NOT NULL 约束拒绝及混合行写入原子性。
    5. 验证 prepared statement 重用、常量折叠、整数/小数转换、underflow-to-zero 与正常有限值不回归。
    6. 回归 pkg/sql/plan/function 相关测试及 PR 描述中的 POWER/EXP/TRIG/数学函数 BVT;记录测试环境、SQL 结果、错误/警告与补测情况。

    建议环境:当前 main merge commit 80d214bef28a33f81020b76b2ed9280a6e7654b9,优先标准 TKE/多 CN + Proxy 验收,并补充本地单机 MySQL 协议验证(如 6001)。

    注意:PR 明确这是 MatrixOne 采用 NULL 语义的行为变更,并不声称恢复 MySQL 8.4 的 error 行为。请 QA 记录该兼容性契约差异;如产品要求严格对齐 MySQL,需要先由产品/RD 明确最终预期。通过后由 QA 关闭 Issue;若失败或契约未决,请保持 open 并记录补修/澄清项。

  12. slyunnn commented on Sep 9, 2026

    @slyunnn

    Regression and extended verification for #28137 (2026-09-09)

    Verification Environment

    • MatrixOne baseline: latest local origin/main at af965c3e4d86ec218de05b585dbafbedb10aa1ae — fix(function): align QUOTE with MySQL (#28443).
    • Related fix: PR #28375, fix: return NULL for POWER EXP and COT arithmetic failures, merged as 80d214bef28a33f81020b76b2ed9280a6e7654b9; the fix commit is an ancestor of the baseline above.
    • Topology: a freshly built standalone MatrixOne deployment from the baseline, with one mo-service hosting LOG, TN, and one CN; no Proxy and no second CN were used.
    • Endpoints: CN MySQL 127.0.0.1:6001; TN 127.0.0.1:19000; Log/HAKeeper 127.0.0.1:32001.
    • Clients and protocol: mysql CLI and MOTR/PyMySQL, both over MySQL wire protocol via TCP to 127.0.0.1:6001.

    What Was Covered

    • OK: Original arithmetic failures return NULL: POWER(-1, 0.5), POW(-2, 0.5), POWER(0, -1), EXP(1000), and COT(0).
    • OK: Happy-path controls remain valid: POWER(2, 3) returns 8; finite EXP(709) and COT(1) return non-NULL values.
    • OK: Boundary controls cover POWER(2, 1024), POWER(2, -1075), EXP(-1000), and the original domain/overflow boundaries.
    • OK: Explicit NULL inputs to POWER, EXP, and COT remain NULL.
    • OK: Mixed three-row vector evaluation proves a bad row is row-local and does not abort valid later rows; COUNT, SUM, and a WHERE ... IS NULL filter observe the resulting NULL values correctly.
    • OK: A CTAS result exposes nullable derived columns, and a nullable target table accepts the mixed POWER/EXP/COT result set.
    • OK: A prepared statement is executed first with invalid values and then with valid values in the same session.
    • OK: Direct MySQL-protocol unhappy-path verification confirms a NOT NULL target rejects a derived NULL with ERROR 3819, and the multi-row INSERT ... SELECT remains atomic with COUNT(*) = 0 afterward.
    • OK: The fix PR's BVT coverage also exercises constant and vector forms, casts, IF/CASE, aggregate/filter behavior, nullable and NOT NULL DML, prepared reuse, and CTAS nullability.
    • Not covered: multi-CN, Proxy, JDBC, and TKE deployment paths; this scalar-function defect has no evidence of topology- or protocol-specific behavior.
    • Not covered: live upstream MySQL comparison. This is intentional: PR fix: return NULL for POWER EXP and COT arithmetic failures #28375 adopts MatrixOne's row-local NULL contract for these arithmetic failures rather than upstream MySQL's error behavior.

    Findings

    PR #28375 supersedes the earlier ERROR 1690 contract considered in the prior assessment. On the current baseline, invalid POWER, EXP, and COT arithmetic yields a row-local NULL; valid rows and subsequent prepared executions continue normally. Nullability metadata and DML behavior are consistent with that contract.

    Large-data regression is not required. The defect is scalar arithmetic and null propagation, not dependent on row count, block/batch boundaries, memory/spill, concurrency, skew, network transfer, or resource scale. The mixed three-row vector case is the minimal stable data set that covers both valid and failing rows without adding unrelated CI cost.

    MOTR / BVT Coverage

    • Added MOTR regression: suites/14_issue_regression/t/issue_28137_null_arithmetic.test and suites/14_issue_regression/r/issue_28137_null_arithmetic.result.
    • Recorded once and replayed twice against the freshly built baseline: each run passed 23 statements with 0 failures.
    • Independent backup branch: test/issue-28137-null-arithmetic, commit fc7957c. No issue-specific PR was created.

    Final Conclusion

    Fixed. The current main contains the related fix, and the original scenario plus functional, unhappy-path, boundary, nullability, prepared-statement, and targeted regression coverage all pass. This comment supersedes the prior Out of scope conclusion; the intended contract is now explicit. Large-data regression is not needed for the reasons above.

  13. added 6 commits that reference this issue on Sep 17, 2026
    95b8efe
    c6e70df
    27aef15
    9bd611a
    1031c53
    e997243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugphase/testing

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions