Repository navigation
Description
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
- MatrixOne: `main`
- MatrixOne commit: `be30a70fe50eac4e8c78e5117fdd69179ba853e0`
- MatrixOne title: `fix(agg): support decimal256 variance aggregates (fix(agg): support decimal256 variance aggregates #28841)`
- Related fix: fix: coerce temporal and string variance operands #28509, merge commit `fffcacc813c9e3b30afb64f18e96e7b21e7ca71e`
- Comparison: MySQL `8.3.0`
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
- The absolute difference is small, but it is observable after `CAST(... AS DECIMAL(24,6))` and can affect comparisons, persisted computed values, and downstream calculations.
- String, date, window, prepared-statement, and binding behavior from [Compatibility]: VAR_* and STDDEV_* reject MySQL numeric-convertible character and temporal operands #28229 were otherwise verified as fixed.
- The current MOTR regression for [Compatibility]: VAR_* and STDDEV_* reject MySQL numeric-convertible character and temporal operands #28229 stabilizes this approximate temporal `VAR_POP` assertion at `DECIMAL(24,3)`; this issue tracks the higher-precision compatibility gap.
Activity
fix(agg): preserve decimal variance precision (#29170)
slyunnn commentedon Sep 21, 2026
Regression and extended verification for #28852 (2026-09-21)
Verification Environment
origin/mainat57c280ed48fdccec3c2eb25042820deaf1eca3c1—fix(sql): complete AES modes and KDF support (#29178).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.1 Log service / 1 TN / 2 CN / Proxy. The rebuilt runtime image wassha256:7783c9cd817a09cd4ccef46672d16e47cfc56857a46b998df0bcbc7c27396a6b, built from the checked-out57c280ed48source. The development image does not embed Git metadata inmo-service --version; its in-container finalizer source was checked and contains thestrconv.FormatFloat(math.Abs(f), 'g', -1, 64)fix.127.0.0.1:6001reachable; CN1127.0.0.1:16001reachable; CN2127.0.0.1:16002reachable.go-sql-driver/mysqlover the MySQL wire protocol usingCOM_QUERY; SQLPREPARE/EXECUTEwas also exercised on the Proxy endpoint. MySQL8.3.0was used as the compatibility control through its MySQL CLI.What Was Covered
CAST(VAR_POP(dt) AS DECIMAL(24,6))andCAST(VAR_POP(ts) AS DECIMAL(24,6))both returned680202686800.666600.680202686800.666600on each endpoint.VAR_POP,VAR_SAMP,STDDEV_POP, andSTDDEV_SAMPfor bothDATETIMEandTIMESTAMPreturned the expectedDECIMAL(24,6)values.PREPARE/EXECUTEwith a bound user variable returned680202686800.666600.NULLvalue returned0.000000forVAR_POPandNULLforVAR_SAMP; all-NULLinput returnedNULLforVAR_POP.DISTINCTcontrol:VAR_POP(DISTINCT dt)remained680202686800.666600after adding a duplicate input value.8.3.0control: the originalDATETIME/TIMESTAMPVAR_POP,DATETIMEVAR_SAMP/STDDEV_POP/STDDEV_SAMP, one-row, all-NULL, and SQL prepared results matched MatrixOne. MySQL8.3.0rejectsVAR_POP(DISTINCT ...), so that MatrixOne-only extension was not used as a cross-engine comparison.mo-testerreplay 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.8.3.0was not separately rerun for theTIMESTAMPVAR_SAMPandSTDDEV_*variants; the issue's two temporalVAR_POPoutputs 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 materialize680202686800.666600at scale6.The focused new aggregate tests and the full
./pkg/sql/colexec/aggexecCGo 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-DECIMALmaterialization 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
test/distributed/cases/function/func_aggr_temporal_fraction.testnow contains the exact#28852DATETIME/TIMESTAMPVAR_POPquery and expectedDECIMAL(24,6)result.2 CNtopology 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.
#28852is fixed on currentmainby#29170/011efc09e0ef2809d6a82defa492d1f923e13fa2. Original, extended, boundary, prepared, three-endpoint, and MySQL8.3.0control checks passed. Large-data regression is not required for the stated scalar conversion reason.