Skip to content

[Bug]: DEGREES exposes and persists infinity for finite DOUBLE input #28485

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked open and closed issues.

#28137 covers the deliberately selected row-local NULL contract for arithmetic failures in POWER, EXP, and COT. No issue was found for non-finite output from DEGREES.

Branch Name

main

Commit ID

f0c31cd4b830be32442cf329e0a3fb08aa9c16c3

Other Environment Information

  • Local standalone MatrixOne built from the commit above
  • Reference: MySQL 8.3.0

Actual Behavior

DEGREES() multiplies a finite DOUBLE by 180/pi without checking whether the result is finite. Inputs above approximately 3.137e306 therefore produce SQL-visible positive or negative infinity:

SELECT DEGREES(CAST('3.14e306' AS DOUBLE));
-- MatrixOne: +Inf
-- MySQL: ERROR 1690, DOUBLE value is out of range

SELECT DEGREES(CAST('-3.14e306' AS DOUBLE));
-- MatrixOne: -Inf
-- MySQL: ERROR 1690, DOUBLE value is out of range

The value is not classified as NULL, compares equal to itself, and can be persisted by CTAS:

CREATE TABLE t AS
  SELECT DEGREES(CAST('3.14e306' AS DOUBLE)) AS v;
SELECT v, v IS NULL, v=v, CAST(v AS CHAR) FROM t;
-- MatrixOne: +Inf, 0, 1, '+Inf'

MySQL aborts the CTAS and does not create the table. In MatrixOne, the infinity also propagates through SUM, AVG, and MAX, so later relational processing treats it as an ordinary value.

The same result occurs with a DOUBLE column and through SQL PREPARE. Positive and negative forms, both CTAS forms, and the prepared forms were each repeated three times.

Expected Behavior

DEGREES() must not expose or persist a non-finite DOUBLE produced from finite SQL input. MySQL raises error 1690. If MatrixOne intentionally applies the row-local arithmetic-failure policy selected for #28137, the overflow row should become NULL; either behavior avoids materializing +Inf/-Inf as ordinary SQL values.

Steps to Reproduce

DROP DATABASE IF EXISTS codex_degrees_overflow;
CREATE DATABASE codex_degrees_overflow;
USE codex_degrees_overflow;

SELECT DEGREES(CAST('3e306' AS DOUBLE));       -- finite control
SELECT DEGREES(CAST('3.14e306' AS DOUBLE));    -- +Inf
SELECT DEGREES(CAST('-3.14e306' AS DOUBLE));   -- -Inf

CREATE TABLE src(id INT PRIMARY KEY, x DOUBLE);
INSERT INTO src VALUES (1,3e306),(2,3.14e306),(3,-3.14e306),(4,NULL);
SELECT id,DEGREES(x) FROM src ORDER BY id;
SELECT SUM(DEGREES(x)),AVG(DEGREES(x)),MAX(DEGREES(x)) FROM src;

PREPARE p FROM 'SELECT DEGREES(?)';
SET @x=CAST('3.14e306' AS DOUBLE);
EXECUTE p USING @x;
DEALLOCATE PREPARE p;

CREATE TABLE t AS
  SELECT DEGREES(CAST('3.14e306' AS DOUBLE)) AS v;
SELECT v,v IS NULL,v=v,CAST(v AS CHAR) FROM t;

Controls

  • DEGREES(1), zero, NULL, and finite results agree with MySQL.
  • DEGREES(CAST('3e306' AS DOUBLE)) remains finite in both engines.
  • RADIANS(CAST('1e308' AS DOUBLE)) remains finite and agrees with MySQL.
  • The server and connection remain healthy after all executions.

Root Cause

builtInDegrees in pkg/sql/plan/function/func_builtin.go uses opUnaryFixedToFixed and directly returns v * (180.0 / math.Pi). It does not check math.IsInf/math.IsNaN. By contrast, the arithmetic-failure implementations for EXP and POWER use *WithNullOnError helpers and reject non-finite intermediate results before appending them.

Activity

  1. added this to the MO-202609 milestone on Sep 9, 2026
  2. added theissue type on Sep 9, 2026
  3. XuPeng-SH commented on Nov 22, 2026

    @XuPeng-SH
    Contributor

    QA 交接:DEGREES 有限输入溢出时返回 SQL NULL

    #32002 已合入 main,合并 SHA d9a43b3156dd6ee54f14bdd4197071e522efd285,最终 PR head a2b88df5。

    独立定向报告确认溢出返回 NULL、CTAS 列可空且未持久化 Infinity。 上述独立 QA 证据对应较早候选 005ea33b,不是当前合并版的实测。正式评审针对较早 head b1bc02f6,最终 head 的 Iceberg E2E 通过;合并队列记录未显示 Required 已满足。未在当前合并提交复跑,不推定 4.2 或整体 CI 通过。

    请在合入树核对正负溢出、正常边界、NULL、预编译和 CTAS 的实际值、可空元数据以及聚合行为。 转测不等于验收通过,工单保持开放。

  4. Ariznawlll commented on Nov 23, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    通过。已在官方 main 测试开始时的最新提交 8f3ec29941cf36f4964f6726ec96e9c6658e2e81 上,验证有限 DOUBLE 输入引起的 DEGREES 溢出不再暴露或持久化 Infinity;正负溢出按当前产品约定分别返回 SQL NULL。本次验证 main,未对 4.2-dev 的行为作结论。

    关键证据

    • 环境:macOS arm64,本地隔离单机 MO(1 CN / 1 TN / 1 LogService),SQL git_version() 返回上述完整 SHA;修复 #32002 合并提交是该测试版本的祖先。
    • 黑盒 Happy:3e306 结果为有限值 1.7188733853924698e+308;零值、NULL、RADIANS(1e308) 控制正常。Unhappy:±3.14e306 分别返回 NULL;包含正常值、正负溢出及 NULL 的同表查询仅对应行变 NULL,SUM、AVG、MAX 忽略 NULL 且 COUNT 为 1。
    • 文本 SQL PREPARE 与 MySQL 二进制预编译都覆盖正负溢出、有限值、NULL 和同一语句的重复绑定;结果符合上述契约。CTAS 生成的 DOUBLE 列可空,写入值为 NULL,IS NULL=1,自比较及转字符均返回 NULL;INSERT SELECT 混合写入后 5 行中仅 1 行非 NULL。
    • 白盒:检查 builtInDegrees 的有限输入溢出判断,并在相同源码版本运行 TestDegreesFiniteOverflowReturnsNull -count=3,通过。黑盒 MOTR 用例通过正式 runner 重复 3 次:3/3,失败及跳过均为 0。
    • 回归已追加到同一 MOTR PR #374,提交 69acc2bfbdaea638850f9789d585613aa3f74449,标记仅运行 main。PR 新一轮 CI 正在执行,不能将其表述为已通过;用户确认可在回归 PR 提交后先关闭,稍后合入。

    待解决点

    无本次验收范围内的阻塞项。MySQL 对该溢出返回错误 1690,MO 当前选择逐行返回 NULL;本次依照研发交接中的 MO 契约验证,并未声称错误码兼容 MySQL。

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