Skip to content

[Compatibility]: temporal VAR_POP differs from MySQL at DECIMAL(24,6) precision #28852

Closed

Description

@slyunnn

Problem

After the type-binding regression in #28229 was fixed, MatrixOne accepts temporal operands for `VAR_POP`, `VAR_SAMP`, `STDDEV_POP`, and `STDDEV_SAMP`. However, for some large `DATETIME` / `TIMESTAMP` numeric values, the aggregate result differs from MySQL at user-observable `DECIMAL(24,6)` precision.

This is a follow-up compatibility issue, not a reopening of #28229: the prior binding-time rejection is fixed.

Environment

Reproduction

```sql
CREATE DATABASE temporal_variance_precision;
USE temporal_variance_precision;

CREATE TABLE t (
id INT PRIMARY KEY,
dt DATETIME,
ts TIMESTAMP
);

INSERT INTO t VALUES
(1, '2024-01-01 01:02:03', '2024-01-01 01:02:03'),
(2, '2024-01-02 02:03:04', '2024-01-02 02:03:04'),
(3, '2024-01-03 03:04:05', '2024-01-03 03:04:05');

SELECT
CAST(VAR_POP(dt) AS DECIMAL(24,6)) AS datetime_var_pop,
CAST(VAR_POP(ts) AS DECIMAL(24,6)) AS timestamp_var_pop
FROM t;
```

Actual Result

MatrixOne:

```text
datetime_var_pop = 680202686800.666624
timestamp_var_pop = 680202686800.666624
```

MySQL `8.3.0`:

```text
datetime_var_pop = 680202686800.666600
timestamp_var_pop = 680202686800.666600
```

Expected Result

For temporal operands subject to MySQL-compatible numeric coercion, MatrixOne should produce a result compatible with MySQL at the requested `DECIMAL(24,6)` precision.

Notes

Activity

  1. added
    kind/bug
    on Sep 14, 2026
  2. added this to the MO-202609 milestone on Sep 14, 2026
  3. added theissue type on Sep 14, 2026
  4. self-assigned this
    on Sep 14, 2026
  5. added a commit that references this issue on Sep 20, 2026
    011efc0
  6. slyunnn commented on Sep 21, 2026

    @slyunnn
    Author

    Regression and extended verification for #28852 (2026-09-21)

    Verification Environment

    • Source: latest origin/main at 57c280ed48fdccec3c2eb25042820deaf1eca3c1 — fix(sql): complete AES modes and KDF support (#29178).
    • Fix under verification: 011efc09e0ef2809d6a82defa492d1f923e13fa2 — fix(agg): preserve decimal variance precision (#29170), which closes #28852. The finalizer converts the finite aggregate result through its shortest round-trip decimal form before applying the target scale.
    • Topology: local 1 Log service / 1 TN / 2 CN / Proxy. The rebuilt runtime image was sha256:7783c9cd817a09cd4ccef46672d16e47cfc56857a46b998df0bcbc7c27396a6b, built from the checked-out 57c280ed48 source. The development image does not embed Git metadata in mo-service --version; its in-container finalizer source was checked and contains the strconv.FormatFloat(math.Abs(f), 'g', -1, 64) fix.
    • Endpoints: Proxy 127.0.0.1:6001 reachable; CN1 127.0.0.1:16001 reachable; CN2 127.0.0.1:16002 reachable.
    • Client protocol: go-sql-driver/mysql over the MySQL wire protocol using COM_QUERY; SQL PREPARE / EXECUTE was also exercised on the Proxy endpoint. MySQL 8.3.0 was used as the compatibility control through its MySQL CLI.

    What Was Covered

    • OK Original reproduction through Proxy: CAST(VAR_POP(dt) AS DECIMAL(24,6)) and CAST(VAR_POP(ts) AS DECIMAL(24,6)) both returned 680202686800.666600.
    • OK Original reproduction directly through CN1 and CN2: both temporal results were 680202686800.666600 on each endpoint.
    • OK Happy path through Proxy: VAR_POP, VAR_SAMP, STDDEV_POP, and STDDEV_SAMP for both DATETIME and TIMESTAMP returned the expected DECIMAL(24,6) values.
    • OK SQL prepared path: PREPARE / EXECUTE with a bound user variable returned 680202686800.666600.
    • OK Boundary and unhappy semantic paths: one non-NULL value returned 0.000000 for VAR_POP and NULL for VAR_SAMP; all-NULL input returned NULL for VAR_POP.
    • OK DISTINCT control: VAR_POP(DISTINCT dt) remained 680202686800.666600 after adding a duplicate input value.
    • OK MySQL 8.3.0 control: the original DATETIME/TIMESTAMP VAR_POP, DATETIME VAR_SAMP/STDDEV_POP/STDDEV_SAMP, one-row, all-NULL, and SQL prepared results matched MatrixOne. MySQL 8.3.0 rejects VAR_POP(DISTINCT ...), so that MatrixOne-only extension was not used as a cross-engine comparison.
    • Not covered: a standalone local mo-tester replay was not available. The exact original SQL is already present in the distributed BVT case and was executed directly against the full running topology by the protocol probe.
    • Not covered: MySQL 8.3.0 was not separately rerun for the TIMESTAMP VAR_SAMP and STDDEV_* variants; the issue's two temporal VAR_POP outputs were both directly compared.

    Findings

    The original precision regression is not reproducible on current main. The former binary-ULP tail (680202686800.666624) is no longer exposed; both temporal types consistently materialize 680202686800.666600 at scale 6.

    The focused new aggregate tests and the full ./pkg/sql/colexec/aggexec CGo package test both passed. They cover rounding neighbors, signs, non-finite/invalid precision errors, DECIMAL64/DECIMAL128, VAR_*/STDDEV_*, DISTINCT, and serialized aggregate-state merge.

    No large-data regression is needed. The defect is a final scalar float64-to-DECIMAL materialization issue, independent of row count, block/batch boundaries, memory/spill, skew, network transfer, or concurrency. The minimum three-row temporal dataset already reaches the affected magnitude and precision boundary.

    MOTR / BVT Coverage

    • Existing MatrixOne distributed BVT test/distributed/cases/function/func_aggr_temporal_fraction.test now contains the exact #28852 DATETIME/TIMESTAMP VAR_POP query and expected DECIMAL(24,6) result.
    • No MOTR change, issue branch, or daily-regression commit was added: creating a duplicate MOTR case would not add coverage beyond the exact upstream BVT plus the completed full-topology protocol replay.
    • No case-level parallel scheduler was used. The 2 CN topology was live, Proxy execution and direct CN1/CN2 execution were verified independently; this is not presented as an engine parallelism stress test.

    Final Conclusion

    Fixed. #28852 is fixed on current main by #29170 / 011efc09e0ef2809d6a82defa492d1f923e13fa2. Original, extended, boundary, prepared, three-endpoint, and MySQL 8.3.0 control checks passed. Large-data regression is not required for the stated scalar conversion reason.

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