Skip to content

[Bug]: LOAD DATA double-rounds Decimal256 text longer than 76 digits (DECIMAL(65,64) stores 2e-64 for 1.4999..95e-64) #29883

Closed

Description

@MatrixAdventurer

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

42d42546fd2c2b2449cb81cea47f81d300139753

Other Environment Information

  • Hardware parameters: Linux amd64
  • OS type: Linux (box), single-node mo-service -launch etc/launch/launch.toml built from the commit above
  • Others: Go 1.27.1

Actual Behavior

When DECIMAL text has more than 76 significant digits, LOAD DATA (CSV and JSONLINE) rounds it twice for a Decimal256 column:

  1. Parse256 rounds at its 76-digit limit;
  2. ParseDecimal256 then rounds again to the column scale.

A carry from step 1 changes the result of step 2. For example, in DECIMAL(65,64) the value 0.<63 zeros>14999999999995 is stored as 2e-64, but the correct result is 1e-64.

path stored value
INSERT '…' / CAST('…' AS DECIMAL(65,64)) 0.000…0001 (correct)
LOAD CSV (also -…, …e0) 0.000…0002 / -0.000…0002
LOAD JSONLINE 0.000…0002 / -0.000…0002

Two more problems in Parse256, same as those fixed for Decimal128 in #29853:

  • Leading zeros of 0.xxx count toward the 76-digit limit, so 0.<76 digits> loses its last digit.
  • An exponent after the dropped digits is ignored, because the loop breaks at the limit.

Expected Behavior

The discarded digits should be rounded exactly once, to the column scale, as with exact decimal arithmetic, half away from zero. Leading zeros should not consume precision, and the exponent should be honoured.

Steps to Reproduce

create table c(id int, d decimal(65,64));
-- /tmp/d256.csv: 1,0.000000000000000000000000000000000000000000000000000000000000000149999999999995
load data infile '/tmp/d256.csv' into table c fields terminated by ',';
select concat('d=', d) from c;   -- d=0.0000000000000000000000000000000000000000000000000000000000000002, expected ...0001

The same happens with format='jsonline'.

Additional information

The Decimal128 counterpart is #29841 / PR #29853. A fix with unit tests (including a randomized comparison against exact big.Rat rounding) and a SQL regression case follows.

Activity

  1. added
    kind/bug
    on Oct 11, 2026
  2. self-assigned this
    on Oct 11, 2026
  3. Ariznawlll commented on Oct 12, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:02a2823c2007d5e4fb4ada148e93743df337551a
    • 部署方式:独立构建的本地单 CN / 单 TN / 单 LogService,隔离数据目录和 SQL 端口
    • 测试日期:2026-10-12

    原问题验证

    将原报告中超过 76 位的 DECIMAL(65,64) 文本(0.000...149999999999995)经普通 INSERT、CSV LOAD、JSONLINE LOAD 写入;三条路径都得到正确的一次舍入结果 0.0000000000000000000000000000000000000000000000000000000000000001,而非原先错误的尾数 ...0002。MOTR compare 模式连续 3 次一致。

    Happy Path 覆盖

    1. 同一边界数的正数、负数、e0 指数写法逐值核对;CSV/JSONLINE 与原生 INSERT 的差集均为 0。
    2. 文本 CAST 与预期的 1e-64 定点值相等,比较结果为 1;不经过二进制浮点计算 golden。

    Unhappy Path 覆盖

    1. CSV 非法数值 not-a-decimal 被拒绝(当前错误码 20101),目标表仍为 3 行,随后 SELECT 1 成功;未将错误码表现扩大解释为该问题的修复范围。

    白盒验证

    本轮仅运行 SQL 黑盒回归;未另跑解析器 UT / -race。因此不宣称所有高精度字符串均已穷尽。

    回归测试

    已在 MOTR PR #229 增加 issue_29883_decimal256_double_round.test 及 golden,本地 compare 3/3 通过;PR 尚待合入。

    测试证据

    • 新增用例与预期结果
    • 本地运行:3 次、每次 19 条语句,57/57 通过;3 种输入路径的正负边界读回完全一致。

    测试结论

    测试通过。

  4. Ariznawlll commented on Oct 12, 2026

    @Ariznawlll
    Collaborator

    回归归档:本 issue 在 MatrixOne main 02a2823c2007d5e4fb4ada148e93743df337551a 上的原问题、正常与边界/异常路径已有上方详细验证记录,MOTR 对应用例本地 compare 3/3 通过。回归 PR https://github.com/matrixorigin/motr/pull/229 已合入(merge commit 0ed4301b164aa42d0affa0dc27e17f7435b7bf04)。据此关闭本 issue;本次关闭未增加先前评论未覆盖的验收范围。

    测试通过。

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

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions