Skip to content

[Compatibility]: DIV result domain differs from MySQL for DECIMAL operands #30158

Closed

Description

@Ariznawlll

Environment

  • MatrixOne: 8.0.30-MatrixOne-v1.3.0, built from 2ce4e58af6f03b943ee288ffad81012766cf830a
  • MySQL: 8.0.46
  • Topology: local single CN / TN / LogService
  • Verification date: 2026-10-14

The official main commit checked during this run is a53390c57de48ac280249ff0e88831e502e20fb0; the tested DIV resolver/executor source is unchanged there from the pinned test build.

Problem

For DECIMAL operands, MatrixOne's DIV result domain does not match MySQL in both published metadata and mixed signedness behavior.

Result metadata for a narrow DECIMAL dividend

CREATE TABLE div_src(d DECIMAL(10,3), i INT);
INSERT INTO div_src VALUES (5.678, 2), (-5.678, -2);

CREATE TABLE div_ctas AS SELECT d DIV i AS q FROM div_src;
CREATE VIEW div_view AS SELECT d DIV i AS q FROM div_src;

SELECT table_name, column_type
FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name IN ('div_ctas','div_view');

Both CTAS and view metadata are stable but differ:

Result MatrixOne MySQL 8.0.46
DECIMAL(10,3) DIV INT BIGINT INT

The values (2 and 2) match. With a DECIMAL(18,3) dividend, both expose BIGINT, making the mismatch specific to the narrower result domain rather than all DECIMAL DIV expressions.

Negative DECIMAL dividend with an UNSIGNED divisor

SELECT CAST(5.678 AS DECIMAL(10,3)) DIV CAST(2 AS UNSIGNED);
SELECT CAST(-5.678 AS DECIMAL(10,3)) DIV CAST(2 AS UNSIGNED);
  • Positive control: both return 2.
  • Negative case: MatrixOne returns -2; MySQL returns ERROR 1690 (22003): BIGINT UNSIGNED value is out of range.
  • DECIMAL(-5.678) DIV SIGNED(2) returns -2 on both engines.
  • The MySQL error persists with empty sql_mode and NO_UNSIGNED_SUBTRACTION; MatrixOne returns -2 in both modes.

These statements were repeated three times with the same outcomes. This is a result-domain/value-error difference, not a division-by-zero or strict-mode failure.

Existing tracking and contract check

The compatibility contract records signed-integer / behavior, but does not define a DECIMAL DIV exception. Closed #23439 covers earlier Decimal64 sign, overflow, and prepared strict-mode issues; it does not cover a signed DECIMAL dividend with an UNSIGNED integer divisor or the narrow-DECIMAL INT metadata shape. #28580 is specifically for /, not DIV. The broader CTAS metadata tracker is #24436.

Expected behavior

Derive the DIV result type and signed/unsigned result domain compatibly with MySQL for DECIMAL/integer operand combinations, including CTAS and views, while preserving the already-matching signed-operand quotient values.

Activity

  1. added this to the MO-202610 milestone on Oct 14, 2026
  2. added
    kind/bug
    on Oct 14, 2026
  3. added
    kind/compatibility
    on Oct 14, 2026
  4. added theissue type on Oct 14, 2026
  5. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充到 DML/ODKU 交叉路径:

    CREATE TABLE div_odku_src(id INT PRIMARY KEY, d DECIMAL(10,3), u BIGINT UNSIGNED);
    INSERT INTO div_odku_src VALUES (1,-5.678,2);
    CREATE TABLE div_odku_dst(id INT PRIMARY KEY, q BIGINT);
    INSERT INTO div_odku_dst VALUES (1,99);
    
    INSERT INTO div_odku_dst
    SELECT id, d DIV u FROM div_odku_src
    ON DUPLICATE KEY UPDATE q=VALUES(q);

    同一操作数形状下,MO 语句成功并将目标行改为 (1,-2);MySQL 报 ERROR 1292 (22007): Truncated incorrect DECIMAL value: '-2',已有目标行保持 (1,99)。这表明前述 signed DECIMAL / unsigned divisor 差异会进入 ODKU 写路径并改变持久化状态;直接 SELECT 的 MySQL 错误码为 1690,DML 上下文中的错误文本/错误码不同。

  6. added
    ai-easy
    on Oct 19, 2026
  7. XuPeng-SH commented on Oct 19, 2026

    @XuPeng-SH
    Contributor

    本轮功能复测结果(2026-10-19 UTC):PR #30171 的 DECIMAL DIV 修复在最新 main 上通过真实 MySQL 协议 SQL 回归及 race 测试。分支 main,完整 SHA 8e63625c4e9baeb1d28c1095c07732f056c04895;Linux/amd64、Go 1.27.1、隔离嵌入式单 CN + MySQL TCP。

    执行 TestDecimalIntegerDivPublicContracts,同一实例完整重复两轮(两轮都通过,数据库清理后确认 schema 不存在),覆盖原 issue 的窄/宽 DECIMAL DIV CTAS 与 VIEW 的 INT/BIGINT 类型域、signed/unsigned 行为,并扩展到 folded/derived/ordered/threshold/null/预备参数重用、uint64 最大值、负非零越界、零与除零 warning 的 sql_mode 对照,以及越界 ODKU 后旧目标行仍保持 q=99。两轮均通过,race 命令 exit 0(40.077s)。

    命令:

    MO_TEST_CLUSTER_TCP_ONLY=1 .agents/skills/mo-dev/scripts/mo-cgo-test -race -p 1 -count=1 -v -timeout=20m -run '^TestDecimalIntegerDivPublicContracts$' ./pkg/tests/sqlintegration
    

    原始日志 SHA-256 0a02199bb745ab63881b2520d59333da9545d10eeb3122158b1c01ec975784b7,环境、命令和退出码在 continue22/runs/30171-main-race/。该 PR 合入 main,本次仅验证 main,未把无关 4.2-dev 当作必测分支。

  8. Ariznawlll commented on Oct 19, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main
    • commit:e0314478159c80b062483c307180b02dc009dbc0(执行前读取的官方 main)
    • 修复:#30171 已 MERGED,merge commit 873282742714436bff407dfcdbbe879147162bd3;GitHub compare 确认该提交在上述 main 内。
    • 部署方式:隔离工作树,Go 1.27.1,macOS/arm64;集成测试启动本地 1 CN / 1 TN / 1 LogService,经真实 MySQL TCP 执行 SQL,启用 Go race。
    • 测试日期:2026-10-20(北京时间)。

    原问题验证

    在上述完整 SHA 独立运行 MO_TEST_CLUSTER_TCP_ONLY=1 .agents/skills/mo-dev/scripts/mo-cgo-test -race -p 1 -count=3 -run '^TestDecimalIntegerDivPublicContracts$' ./pkg/tests/sqlintegration,exit 0,ok .../pkg/tests/sqlintegration 77.953s。该测试每次运行独立建库/清库两轮,因此原始 SQL 形状累计 6/6:

    • DECIMAL(10,3) DIV INT 的 CTAS 与 VIEW 的 information_schema.columns.column_type 均为 int,查询值 2;DECIMAL(18,3) DIV INT 为 bigint、值 2,与 issue 的窄/宽对照一致。
    • 负 DECIMAL 除以 UNSIGNED 的原始 SELECT 不再错误返回 -2,而是 out of range;正值对照返回 2。
    • 原始 INSERT ... SELECT d DIV u ... ON DUPLICATE KEY UPDATE 被拒绝后,目标旧行 q=99 保持不变;不会再持久化错误的 -2。

    Happy Path 覆盖

    1. 窄/宽 DECIMAL、带符号与无符号除数、CTAS/VIEW 及视图再消费的列类型和值均由同一真实 TCP 测试断言,累计 6/6 轮通过。
    2. 常量折叠、派生表、排序/LIMIT、精度阈值、UINT64 最大值均有精确类型/值断言;预备语句在 signed/unsigned 参数间复用后,合法结果仍正确。
    3. 合法 NULL 输入与零分母按对应 SQL mode 返回 NULL/警告;测试区分有效 NULL 与错误路径,不将其算作异常失败。

    Unhappy Path 覆盖

    1. 负 DECIMAL / UNSIGNED 在直接 SELECT、VIEW、预备语句复用时均按 out of range 拒绝;失败后同连接合法查询继续成功。
    2. ODKU 写路径的同类越界拒绝,目标表原值 99 保持不变,验证失败原子性。
    3. 每轮检查测试数据库已删除,累计 6/6 无残留。未执行外部故障注入;本缺陷由确定性 SQL 类型/数值路径触发,不依赖外部故障。

    白盒验证

    同 SHA 上述真实协议集成测试以 -race -count=3 通过,覆盖表达式类型推断、执行器和持久化消费;不是只运行 planner 单元测试。未观察到 race 报告或 panic。

    回归测试

    测试证据

    • 上述完整 SHA 的定向命令 exit 0、耗时 77.953s;具体值/类型/失败后状态的断言可在链接的 Go 测试与 SQL/result 配对文件中逐项核对。
    • 修复 PR 与 CI;本轮只验收官方 main,不声称 4.2 发布线已验证。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

ai-easyarea/compatibilitykind/bugkind/compatibility

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions