Repository navigation
Description
Summary
VAR_POP, VAR_SAMP, and VARIANCE on a large-range DECIMAL column fail because MatrixOne declares a DECIMAL return type and attempts to convert the floating variance back into DECIMAL(38,12). MySQL specifies DOUBLE for numeric variance and standard-deviation aggregates. The same input succeeds after an explicit DOUBLE cast.
This is distinct from the already closed small-variance accuracy issue: the present case deterministically raises an error instead of returning any variance.
Environment
- MatrixOne official
main:99ed717b769e261b842c2f17345bd65865fc1470 - Clean local single-CN build and isolated data directory
- Reproduced identically in 3/3 runs
Reproduction
CREATE TABLE d (id INT PRIMARY KEY, v DECIMAL(30,10) NOT NULL);
INSERT INTO d VALUES
(1, 9007199254740993.1234567890),
(2, -12.5000000000),
(3, 0.0000000001);
SELECT SUM(v), AVG(v) FROM d;
-- 9007199254740980.6234567891 | 3002399751580326.874485596367
SELECT VAR_POP(v) FROM d;Actual result:
ERROR 20301 (HY000): invalid input: Can't convert Float64 To Decimal128: ... (38,12)
VAR_SAMP(v), VARIANCE(v), and VAR_POP(v) OVER () fail the same way. STDDEV_POP/STDDEV_SAMP happen to return because the square root is small enough for the DECIMAL result range.
Scope control
SELECT VAR_POP(CAST(v AS DOUBLE)) FROM d;
-- returns an approximate variance
SELECT VAR_POP(CAST(1.1 AS DECIMAL(10,4))),
STDDEV_POP(CAST(1.1 AS DECIMAL(10,4)));
-- small DECIMAL values return normallyThe failure therefore depends on the DECIMAL return conversion range, not on input parsing, aggregation state construction, or the mathematical variance computation itself.
Expected behavior
For numeric inputs, MySQL documents VAR_POP, VAR_SAMP, VARIANCE, and standard-deviation functions as returning DOUBLE. MatrixOne should not reject a valid high-range DECIMAL variance merely because it routes the result through a fixed-scale DECIMAL type; it should return an approximate DOUBLE result consistent with that contract.
Preliminary code observation
VarStdDevReturnType selects AvgReturnType for DECIMAL input, while the aggregate state and result calculation are float64-based. The final conversion then calls Decimal128FromFloat64(..., 38, scale), which fails when the variance exceeds the integer range left by the scale. This is a diagnosis hypothesis, not a proposed fix.
Suggested regression coverage
Cover DECIMAL input with variance above DECIMAL(38,12) integer range for VAR_POP, VAR_SAMP, VARIANCE, and window VAR_POP; assert an approximate DOUBLE result. Include small DECIMAL and explicit DOUBLE controls.
Activity
Ariznawlll commentedon Oct 14, 2026
当前本地 runtime 复核
在 MatrixOne
8.0.30-MatrixOne-v1.3.0(源码 revision2ce4e58af6f03b943ee288ffad81012766cf830a)和隔离 MySQL8.0.45上执行 issue 中的高范围DECIMAL(30,10)样本:MySQL 8.0.45 返回
1.8028808536579298e31,2.7043212804868946e31,1.8028808536579298e31,4.246034448350519e15。MatrixOne 的前三项均在转换到Decimal128(38,12)时返回ERROR 20301: ... beyond the range, can't be converted to Decimal128(38,12);相邻的STDDEV_POP单独查询可返回值。该路径在当前本地服务仍可复现。XuPeng-SH commentedon Oct 24, 2026
Tracking consolidated into #28230. The canonical issue now includes this report's independent scope and acceptance criteria. This is administrative consolidation, not a claim that the defect is fixed; the original reproduction and discussion are preserved here.