You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
d256Mul panics for valid Decimal256 operands when the scale reduction is more
than 38 digits. The multiplication fast tiers call scalePow10Factors, which
indexes types.Pow10 past its 20-entry range.
Reproduction
On origin/main at f9a44447743fff827dab01300837d27a3d9811f0:
runtime error: index out of range [57] with length 20
github.com/matrixorigin/matrixone/pkg/sql/plan/function.scalePow10Factors
DECIMAL(76,76) is a valid Decimal256 type, and 1 * 1 should produce a
zero/one value after the target-scale reduction. A user query can therefore
crash the process instead of returning a result or a controlled overflow.
Root cause
scalePow10Factors(n) supports only the two-limb representation for n <= 38, but the Decimal256 multiplication path can receive scale-down
values up to 76. The int32/int64 fast tiers do not guard that range before
indexing types.Pow10[n-19].
Expected fix
Use a bounded generic scale-down path for n > 38 (or reject it with a normal
arithmetic error), without indexing types.Pow10 out of bounds. Preserve the
existing int32/int64 fast paths for their supported range and add tests for
all vector/broadcast layouts, NULL rows, scale 38/39/57/76, and overflow/error
semantics.
Related: #28875 (the raw-overflow Decimal256 multiplication fallback).
定向 Go UT:3/3 通过;测试命令为 go test -vet=off ./pkg/sql/plan/function -count=3 -run '^(TestD256MulScaledRawOverflow|TestD256MulScaledRawOverflowPreservesOverflow|TestD256MulScaledFallbackChunkBoundaries|TestD256MulHighScaleSmallValues)$'。
Activity
XuPeng-SH commentedon Sep 14, 2026
Fix queued in PR #28878: #28878. The unified high-scale dispatch prevents
scalePow10Factorsout-of-range access while preserving the <=38 fast paths.fix(decimal): handle Decimal256 wide multiplication scale reduction (#…
Ariznawlll commentedon Sep 15, 2026
测试版本
main:0c3a04f390adaf6281fd592a49778ea5b1155e67原问题验证
复现高 scale Decimal256 乘法的缩 scale 分支;不再 panic,结果可正常返回。
Happy Path 覆盖
覆盖 raw product 经缩 scale 后可表示、边界 scale 以及小值高 scale 乘法。
Unhappy Path 覆盖
覆盖超过 Decimal256 可表示范围的输入,确认返回受控溢出错误而非 panic。
白盒验证
pkg/sql/plan/function中TestD256MulScaledRawOverflow、TestD256MulScaledRawOverflowPreservesOverflow、TestD256MulScaledFallbackChunkBoundaries、TestD256MulHighScaleSmallValues连续 3 次通过。回归测试
该问题属于内部 Decimal256 宽算术内核;公开 SQL 不提供可用于 MOTR 的
DECIMAL256声明,故以已有 MatrixOne 定向 UT 作为回归门禁,不强行加入 MOTR。测试证据
定向 Go UT:3/3 通过;测试命令为
go test -vet=off ./pkg/sql/plan/function -count=3 -run '^(TestD256MulScaledRawOverflow|TestD256MulScaledRawOverflowPreservesOverflow|TestD256MulScaledFallbackChunkBoundaries|TestD256MulHighScaleSmallValues)$'。测试结论
测试通过。
fix(decimal): handle Decimal256 wide multiplication scale reduction (m…
fix(decimal): handle Decimal256 wide multiplication scale reduction (m…
fix(decimal): handle Decimal256 wide multiplication scale reduction (m…