Skip to content

[Compatibility]: high-range DECIMAL VAR_POP errors instead of returning DOUBLE #28131

Closed as not planned

Description

@Ariznawlll

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 normally

The 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

  1. added
    kind/bug
    on Sep 4, 2026
  2. added this to the MO-202609 milestone on Sep 4, 2026
  3. added theissue type on Sep 4, 2026
  4. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    当前本地 runtime 复核

    在 MatrixOne 8.0.30-MatrixOne-v1.3.0(源码 revision 2ce4e58af6f03b943ee288ffad81012766cf830a)和隔离 MySQL 8.0.45 上执行 issue 中的高范围 DECIMAL(30,10) 样本:

    WITH vals AS (
      SELECT CAST('9007199254740993.1234567890' AS DECIMAL(30,10)) x UNION ALL
      SELECT CAST('-12.5000000000' AS DECIMAL(30,10)) UNION ALL
      SELECT CAST('0.0000000001' AS DECIMAL(30,10))
    )
    SELECT VAR_POP(x), VAR_SAMP(x), VARIANCE(x), STDDEV_POP(x) FROM vals;

    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 单独查询可返回值。该路径在当前本地服务仍可复现。

  5. XuPeng-SH commented on Oct 24, 2026

    @XuPeng-SH
    Contributor

    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.

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions