Skip to content

[Bug]: ABS(-0.0) preserves negative zero and changes ATAN2 results #30152

Closed

Description

@Ariznawlll

Summary

For a floating-point negative zero, MatrixOne's ABS() preserves the negative sign. This differs from MySQL and changes downstream functions that observe the sign of zero. For example, ATAN2(ABS(-0e0), -1e0) returns -π in MatrixOne but +π in MySQL; a predicate comparing that result to PI() consequently omits a matching row.

Environment

  • MatrixOne runtime used for the SQL comparison: 8.0.30-MatrixOne-v1.3.0 (local single-CN/TN/LogService environment; the running server binary SHA was unavailable).
  • Current official main checked at a53390c57de48ac280249ff0e88831e502e20fb0. Its AbsSigned implementation still uses if v < 0 { v = -v }, so IEEE negative zero is not normalized. The FLOAT/DOUBLE ABS caller uses this function:
  • Comparison server: MySQL 8.0.46.

Minimal reproduction

SELECT ABS(-0e0), ATAN2(ABS(-0e0), -1e0),
       ATAN2(ABS(-0e0), -1e0) = PI();

Observed output, repeated 3/3:

Server ABS(-0e0) ATAN2(...) ATAN2(...) = PI()
MatrixOne -0 -3.141592653589793 0
MySQL 0 3.141592653589793 1

The row-level form also reproduces the result difference:

CREATE TABLE abs_zero_filter(id INT PRIMARY KEY, f DOUBLE);
INSERT INTO abs_zero_filter VALUES (1, -0e0), (2, 0e0), (3, -2.5), (4, 2.5);
SELECT id
FROM abs_zero_filter
WHERE ATAN2(ABS(f), -1e0) = PI()
ORDER BY id;
  • MatrixOne returns 2.
  • MySQL returns 1, 2.

This row-filter difference was also reproduced 3/3. Controls WHERE f = 0 and WHERE ABS(f) = 0 return both zero rows on both servers; nonzero ABS()/ATAN2() results match.

Expected behavior

ABS(-0e0) should produce positive zero, as it does in MySQL. Downstream expressions such as ATAN2(ABS(-0e0), -1e0) should therefore produce +π, and the equality predicate with PI() should retain the row.

Scope and related reports

This is a wrong-result bug in the supported floating-point ABS() path, not an unavailable function. Existing signed-zero reports such as #28695 (secondary-index equality) and #28856 (HLL distinct aggregation) concern different execution paths and do not cover ABS() followed by a sign-sensitive math function. No exact duplicate for this function composition was found.

A regression should check the sign of zero at the ABS() boundary and a downstream sign-sensitive function/predicate; no test file was added as part of this report.

Activity

  1. added this to the MO-202610 milestone on Oct 14, 2026
  2. added
    kind/bug
    on Oct 14, 2026
  3. added theissue type on Oct 14, 2026
  4. added
    ai-easy
    on Oct 15, 2026
  5. Ariznawlll commented on Oct 15, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:17a6200f59e764729e5544908fffd5480ae88279
    • 修复:MatrixOne PR #30168,已合入上述官方 main
    • 部署方式:本地隔离 embedded MatrixOne,1 CN + 1 TN + 1 Log Service;独立数据库,无共享集群
    • 测试日期:2026-10-15(Asia/Shanghai)

    原问题验证

    ABS(-0e0) 返回正零;本地驱动读取后 math.Signbit 为 false。ATAN2(ABS(-0e0),-1e0) 为正 π(误差小于 1e-12),与 PI() 的 SQL 比较为 true。原始路径和 MOTR 定向用例各 3 次通过。

    Happy Path 覆盖

    1. 正零对照 ATAN2(ABS(0e0),-1e0)=PI() 为 true。
    2. 表中 -0e0 与 0e0 经 ABS 后均满足过滤条件,按 id 排序返回准确两行 1,2;-2.5 和 2.5 不误入该过滤结果。
    3. 普通非零值的 ABS(-2.5)、ABS(2.5) 均为 2.5;ABS(NULL) 保持 NULL。

    Unhappy Path 覆盖

    不适用:此缺陷针对合法浮点负零的符号及后续计算,不涉及错误输入拒绝或失败回滚。NULL 作为有效边界单独验证。

    白盒验证

    不适用:公开 SQL 和客户端浮点符号检查已覆盖原现象;未做内部故障注入或 -race。

    回归测试

    • MatrixOne 已有 BVT:test/distributed/cases/function/func_math_abs.test;其 PR 的 TKE 镜像构建检查失败,相关 BVT job 被跳过。
    • 已补 MOTR:suites/14_issue_regression/t/issue_30152_abs_signed_zero.test,见 motr PR #240。本地 3/3 通过;PR 的 4 项离线检查通过,但尚未合入、集成 MOTR CI 尚未验证。按本次要求先关闭 issue;持续回归正式生效仍待 PR 合入。
    • 不需 big-data、stability 或 chaos:负零现象是确定性标量/过滤语义,不依赖规模或外部故障。

    测试证据

    • MOTR PR #240 的负零回归用例
    • 本地隔离运行:5 个 MOTR 定向 case × 3 轮,15/15 成功、147/147 SQL/场景语句成功;本 issue 对应用例 3/3 成功。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions