Repository navigation
Description
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 1690The 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:
- Crashes downstream JSON serialization — verified concretely:
SELECT JSON_OBJECT('v', VARIANCE(x)) FROM ...same input...;
-- MO: ERROR 20301: invalid input: invalid JSON vector payloadSo 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.
- Text output is non-SQL:
+Infinityis 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 payloadImpact
- Statistical/dashboards queries containing extreme-magnitude data (log-scale scientific values, ML feature variance) silently produce
+Infinityrows, 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
fix: correct ROUND/TRUNCATE extreme-digits overflow and make VARIANCE…
fix: correct ROUND/TRUNCATE extreme-digits overflow and make VARIANCE…
fix: correct ROUND/TRUNCATE extreme-digits overflow and make VARIANCE…
fix: correct ROUND/TRUNCATE extreme-digits overflow and make VARIANCE…
fix: correct ROUND/TRUNCATE extreme-digits overflow and make VARIANCE…
XuPeng-SH commentedon Oct 28, 2026
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
f847803on 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.Ariznawlll commentedon Oct 28, 2026
结论
测试通过。原始 VARIANCE 溢出和 JSON 消费路径返回明确的范围错误,有限 STDDEV 保持正确。
关键证据
main@f847803802289b2b2d0df4f0a2f842c2804b823a,macOS/arm64,隔离 1 CN + 1 TN + 1 Log,2026-10-28;二进制版本一致,修复 #31434 merge commit14888d457fb9193b5188065151936091344dc9df在祖先链。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。待解决点