Repository navigation
Description
AVG over a valid DECIMAL(34,0) column fails with 20301 Decimal128 Add overflow at 17015 identical rows, although the exact average is representable. Adding one digit of declared input precision makes the same data succeed.
Reproduced twice on official main 6a2b29954749d5a47820ed429cfa8a6c4793682f; SQL git_version() returned 6a2b299547. Both rounds used fresh databases on one owned local instance, with 2 CPU / 4 GiB limits.
This is the executed reproduction method: insert real table rows with PyMySQL in batches of 256, then query the stored DECIMAL column. Set MO_TEST_PASSWORD and optionally MO_TEST_PORT for the target instance.
import os
import pymysql
conn = pymysql.connect(
host="127.0.0.1", port=int(os.getenv("MO_TEST_PORT", "6001")),
user="root", password=os.environ["MO_TEST_PASSWORD"], autocommit=True,
connect_timeout=5, read_timeout=20, write_timeout=20,
)
created = False
try:
with conn.cursor() as c:
c.execute("SELECT git_version()")
actual_sha = str(c.fetchone()[0])
assert len(actual_sha) >= 8 and "6a2b29954749d5a47820ed429cfa8a6c4793682f".startswith(actual_sha)
c.execute("CREATE DATABASE avg_decimal34_capacity_repro")
created = True
c.execute("USE avg_decimal34_capacity_repro")
c.execute("CREATE TABLE t(id INT PRIMARY KEY, d DECIMAL(34,0))")
value = "9" * 34
for start in range(1, 17016, 256):
c.executemany(
"INSERT INTO t(id,d) VALUES(%s,%s)",
[(i, value) for i in range(start, min(start+256, 17016))],
)
for sql in [
"SELECT COUNT(*), MIN(d), MAX(d), SUM(d) FROM t",
"SELECT AVG(d) FROM t WHERE id <= 17014",
"SELECT AVG(d) FROM t",
"SELECT AVG(CAST(d AS DECIMAL(35,0))) FROM t",
]:
try:
c.execute(sql)
print(sql, c.fetchall())
except pymysql.MySQLError as e:
print(sql, e.args)
finally:
try:
if created:
with conn.cursor() as c:
c.execute("DROP DATABASE avg_decimal34_capacity_repro")
finally:
conn.close()Observed in both rounds:
| Query | Result |
|---|---|
| COUNT / MIN / MAX / SUM | Exact fixture verified: 17015 copies of 10^34-1; SUM=170149999999999999999999999999999982985 |
| AVG over first 17014 rows | 9999999999999999999999999999999999.0000 |
| AVG over all 17015 rows | 20301 Decimal128 Add overflow |
| AVG after casting the same values to DECIMAL(35,0) | 9999999999999999999999999999999999.0000 |
Expected: both row counts return that same exact average. For v=10^34-1, 17014*v <= 2^127-1 < 17015*v, but the final mean v.0000 fits the declared DECIMAL(38,4) result. The overflow belongs to the intermediate accumulator.
AvgReturnType keeps precision34 in Decimal128; makeSumAvgExec selects sumDecimal128FastExec with a Decimal128 sum state. Precision35 promotes to Decimal256. A focused production UT confirms the 17014/17015 boundary for constant and flat vectors, negative values, and order-dependent cancellation; the 35-digit and alternating-order controls pass. No accumulator state was injected. The public promoted-precision control succeeded after each error, and both owned databases were dropped with catalog count 0.
Related: #28230 (OPEN aggregate-precision umbrella), #28585 (SUM accumulation widening), #27855 (high-precision AVG result/division). The new evidence concerns AVG's intermediate capacity at precision34; it does not establish the cause of the original BigData DECIMAL(16,6) golden-result differences.
Source at the tested commit: AVG result-type selection, executor dispatch, Decimal128 sum state.
The public error in both executions was:
(20301, 'invalid input: Decimal128 Add overflow: 168959999999999999999999999999999983104+1189999999999999999999999999999999881')
Current-main status was rechecked before filing. Searches of open and closed AVG/overflow/precision34 issues and the related issue bodies/comments found no exact tracker for this boundary. #28230's currently listed acceptance covers MEDIAN, high-range variance, and SUM metadata; it does not include this AVG accumulation reproduction. This can be linked under that numeric umbrella while retaining an independently reproducible AVG acceptance case.
Activity
MatrixAdventurer commentedon Nov 10, 2026
分级建议:severity/s1 —— 确定性聚合数据错误:结果本身可表示,却因中间累加器选择(precision34 走 Decimal128 累加态)在特定行数边界必现溢出报错,属必现逻辑/数据错误。
模块:pkg/sql/colexec/aggexec(sumavg2.go 的 AvgReturnType/makeSumAvgExec 与 sum_decimal_fast.go 的 Decimal128 sum state)。
疑似重复:未见单条完全重复;建议挂到 open 的聚合精度 umbrella #28230 下,相邻案例 #28585、#27855 可一并参考。
建议负责人:aunjgr(aggexec 路径近期提交者)。
本操作由LW授权的MOI智能体提交
gouhongshen commentedon Nov 10, 2026
PR #32488 is trying to fix this issue.
fix(aggexec): widen AVG sum state to Decimal256 for DECIMAL(29..34) (#…
gouhongshen commentedon Nov 10, 2026
PR #32488 has merged and is awaiting manual validation. The issue remains open.
XuPeng-SH commentedon Nov 10, 2026
QA 交接:DECIMAL(34,0) AVG 中间累加溢出
#32488 已于 2026-11-10 18:48:59 UTC 合入 main,merge SHA
4c701ab3da4d2c36e9845b2d72c3c74436b87b88,最终 head8bf8848b60a2acd48da66e629708e855cec78b6b。已核对本 issue 完整评论、PR 完整 diff、评审和合并状态;未见当前适用的新反例或未完成开发 follow-up。本项是产品 AVG 正确性问题,不是 CI flaky issue,转交 Ariznawlll 复测,保持 open;这不是验收通过。修复范围:AVG 输入 DECIMAL(29..34) 改用 Decimal256 累加态,在宽域计算均值后按原声明精度收窄,保留 Decimal128 公开结果类型。覆盖 DISTINCT、普通分组和窗口路径;零计数组为 NULL。SUM、宽度 ≤28 的既有快路径及 ≥35 的已提升路径不因本次改动宣称全面扩容;#28230 总项及原始 DECIMAL(16,6) golden 差异不由本项验收替代。
已有证据(均为远端记录,不是本轮本地实测):
6150dc49dfc96a7f8654de7676674dc5ba5c99cb报告 aggexec 全包 3177 项 test/subtest 通过、codec round-trip/window snapshot/27 个 Flush 分配故障探针通过,以及单 embedded CN 的 17 条 MySQL fixture 两轮通过;评审未独立重跑正常 mo-tester。建议 QA 在包含该 merge 的 main 上重放本 issue 的真实表 17014/17015 行边界及精度35对照,确认 COUNT/MIN/MAX/SUM fixture 和 AVG 精确值;运行新增 avg_decimal34_boundary BVT 并检查 CTAS/JDBC 元数据。补充不同 scale、负值/NULL/空组、distinct 真正跨累加边界、正负抵消、窗口与分布式 partial merge/序列化边界。每个累加组的和状态由16字节增至32字节,组数较多时注意账户内存和错误清理;本轮未验证多 CN、大数据量、高并发或性能。上述边界建议不构成要求自动 backport 到4.2。
slyunnn commentedon Nov 13, 2026
Regression and extended verification for #32429 (2026-11-13)
Verification Environment
Target:
main@a626dd045a656c801b6730732adc16df056379d3, fix(disttae): preserve table ownership for clone deletes (#32555), frozen from remote at test start. Fresh Go1.27.1release build with matching native libraries; actualgit_version()=a626dd045aconfirmed at each endpoint. No MatrixOne service source was modified.Topology: local macOS arm64,
2 CN / 1 TN / 1 Log service / Proxy. Proxy127.0.0.1:6001, CN1127.0.0.1:16001, CN2127.0.0.1:16002were connected and actually exercised through PyMySQL text protocol and Java/JDBC BVT. Each issue's original SQL ran on all three endpoints. BVT/shared catalog operations ran serially; runner concurrency is not presented as forced engine parallelism.What Was Covered
256, exact COUNT/MIN/MAX/SUM oracle, and AVG at17,014/17,015rows: exact representable result on all endpoints.DECIMAL(38,4)metadata.17,015genuinely distinct near-maximum values crosses the accumulator boundary; exact mean checked independently with Python Decimal. Running window result checked at the boundary.17,015rows;17/17statements per endpoint,51/51total, with metadata comparison.16896+119partial-state merge, codec roundtrip, window state, dispatch/result narrowing and error propagation. The complete aggexec package passed.Findings
Associated repair: PR #32488, fix(aggexec): widen AVG sum state to Decimal256 for DECIMAL(29..34), merge
4c701ab3da4d2c36e9845b2d72c3c74436b87b88(targetmain).DECIMAL(29..34) AVG uses the wider internal sum state while preserving the public result contract. The original intermediate overflow did not recur; exact positive/negative and distinct/window results matched the independent oracle. SUM and the separate #28230 umbrella are not declared fully repaired by this acceptance.
Large-data regression required: Yes, the row-count/accumulator boundary must be crossed. The actual
17,014/17,015fixtures, genuinely distinct boundary and34,030-row grouped BVT did so. Further volume or TKE would not strengthen this specific arithmetic-capacity proof; production group-cardinality memory cost is not claimed.MOTR / BVT Coverage
Reused the existing issue-specific cases and focused tests described above; no duplicate MOTR case/commit or empty PR was created. The four-owner focused run passed
46top-level tests; the additional SHOW protocol selection passed. Normal service and temporary fixture changes remained outside tracked source. No full CI/race result is inferred from focused local evidence.Final Conclusion
Fixed — The reported precision34 AVG intermediate-capacity defect is fixed on this main commit. No
4.2-devbackport acceptance is implied.