Skip to content

[Bug]: VARIANCE overflow returns +Infinity and breaks JSON_OBJECT #31355

Closed

Description

@Ariznawlll

DRAFT ISSUE 29 (候选, 不要提交)

标题候选: [Bug]: VARIANCE/STDDEV overflows return IEEE "+Infinity" — non-JSON-serializable, breaks json_object with "invalid JSON vector payload" (MySQL raises ERROR 1690)

标签: kind/bug, needs-triage

Description

When VARIANCE (and the related family) overflows its double range, MatrixOne returns the literal IEEE +Infinity while MySQL raises ERROR 1690 (DOUBLE value is out of range in 'variance(...)').

Verified (main, 2026-10-26):

SELECT VARIANCE(x) FROM
  (SELECT CAST(1e200 AS DOUBLE) AS x UNION ALL SELECT CAST(-1e200 AS DOUBLE)) t;
-- MO   : +Infinity          (special float token)
-- MySQL: ERROR 1690: DOUBLE value is out of range in 'variance(`t`.`x`)'

SELECT STDDEV(x) FROM ...same input...;
-- MO   : +1e200 (finite correct value — actually stronger than MySQL here)
-- MySQL: ERROR 1690

The underlying STDDEV result is genuinely finite here (MO computes what MySQL refuses — that half is arguably an advantage). The problem is the VARIANCE result: it is a true IEEE (2\times10^{400}), which overflows to +Inf. MO passes the +Inf through to the client as a raw double token (+Infinity), which then:

  1. Crashes downstream JSON serialization — verified concretely:
SELECT JSON_OBJECT('v', VARIANCE(x)) FROM ...same input...;
-- MO: ERROR 20301: invalid input: invalid JSON vector payload

So the same query that "works" in one context errors inside JSON_OBJECT with a message that gives no hint about the overflow being the cause.

  1. Text output is non-SQL: +Infinity is not a valid MySQL numeric token; parsers expecting MySQL text format (period exporters, COPY pipelines to other DBs) fail on it.

Reproduction

SET SESSION sql_mode='';
SELECT VARIANCE(x) FROM (SELECT CAST(1e200 AS DOUBLE) AS x UNION ALL SELECT CAST(-1e200 AS DOUBLE)) t;
-- +Infinity
SELECT JSON_OBJECT('v', VARIANCE(x)) FROM (SELECT CAST(1e200 AS DOUBLE) AS x UNION ALL SELECT CAST(-1e200 AS DOUBLE)) t;
-- ERROR invalid JSON vector payload

Impact

  • Statistical/dashboards queries containing extreme-magnitude data (log-scale scientific values, ML feature variance) silently produce +Infinity rows, breaking export/serialization (as shown) and displaying as a weird token rather than an actionable error or a documented NULL.
  • The error surfaced in JSON path (invalid JSON vector payload) misleads debugging entirely — tracing it back to the overflow requires deep luck.
  • Cross-engine result divergence: MySQL refuses early with 1690, giving the user a chance to use a scaled input; MO leaves the bad value in flight.

Expected behavior

Match MySQL: raise ERROR 1690 (22003): DOUBLE value is out of range in 'variance(...)' when the true variance overflows the double range, or (documented alternative) return NULL with a warning. The STDDEV finite path that currently succeeds is a nice-to-keep and compatible with part of MySQL's behavior matrix anyway; only the +Inf propagation needs the guard before it reaches serialization/JSON vectors.

Activity

  1. added
    kind/bug
    on Oct 27, 2026
  2. added this to the MO-202610 milestone on Oct 27, 2026
  3. added theissue type on Oct 27, 2026
  4. XuPeng-SH commented on Oct 28, 2026

    @XuPeng-SH
    Contributor

    QA status for merged main 14888d457fb9193b5188065151936091344dc9df (#31434): this environment did not execute the VARIANCE/STDDEV implementation or SQL tests because resource headroom was insufficient.

    Subsequently Ariznawlll independently verified f847803 on an isolated macOS/arm64 service: VARIANCE overflow and its JSON consumer returned 1690, finite STDDEV, singleton and NULL controls passed 3/3, and the connection recovered. Focused MOTR passed 3/3; the full MOTR suite was not run. See #31355 (comment). These are independent results, not tests performed in this environment.

  5. assigned and unassigned on Oct 28, 2026
  6. Ariznawlll commented on Oct 28, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。原始 VARIANCE 溢出和 JSON 消费路径返回明确的范围错误,有限 STDDEV 保持正确。

    关键证据

    • main@f847803802289b2b2d0df4f0a2f842c2804b823a,macOS/arm64,隔离 1 CN + 1 TN + 1 Log,2026-10-28;二进制版本一致,修复 #31434 merge commit 14888d457fb9193b5188065151936091344dc9df 在祖先链。
    • VARIANCE(±1e200) 和 JSON_OBJECT 消费同一结果均 3/3 返回 1690 out of range;STDDEV 3/3 返回有限 1e200。单行 5 的 VARIANCE/VAR_SAMP/STDDEV 为 (0,NULL,0),全 NULL 为 (NULL,NULL,NULL),错误后连接 SELECT 1 返回 1。
    • MOTR 场景 定向 3/3;修复 PR CI UT、SCA、PROXY 和 PESSIMISTIC BVT 通过。

    待解决点

    • 完整 MOTR suite 未运行,MOTR 新 head CI 发布时仍在运行。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions