Skip to content

[Compatibility]: div_precision_increment is accepted but ignored by DECIMAL division #28594

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues, including open and closed issues.

Branch Name

main

Commit ID

fc621e3

Other Environment Information

  • MatrixOne: locally built from the commit above (8.0.30-MatrixOne-v1.3.0)
  • MySQL baseline: 8.0.46
  • Verification date: 2026-09-10

Actual Behavior

MatrixOne exposes div_precision_increment as a dynamic global/session variable and accepts new session values, but the variable has no effect on exact DECIMAL division. The quotient value, number of fractional digits, result precision/scale, CTAS schema, and prepared execution remain fixed after the variable changes.

For DECIMAL(10,2) / DECIMAL(10,2), MatrixOne always returns eight fractional digits and CTAS always creates DECIMAL(38,8):

div_precision_increment  MatrixOne value  MatrixOne CTAS type
0                        0.33333333       DECIMAL(38,8)
4                        0.33333333       DECIMAL(38,8)
10                       0.33333333       DECIMAL(38,8)
30                       0.33333333       DECIMAL(38,8)

SELECT @@session.div_precision_increment does report 0, 4, 10, and 30 after each SET, so the setting is stored but not consumed by division.

MySQL 8.0.46 applies the same setting to both value precision and metadata:

div_precision_increment  MySQL value                         MySQL CTAS type
0                        0.33                                DECIMAL(12,2)
4                        0.333333                            DECIMAL(16,6)
10                       0.333333333333                      DECIMAL(22,12)
30                       0.333333333333333333333333333333    DECIMAL(42,30)

The mismatch also affects Decimal256 input. With DECIMAL(50,10) / 3, MatrixOne always returns scale 12 and CTAS always creates DECIMAL(65,12), while MySQL uses scales 10, 14, 20, and 30 for increments 0, 4, 10, and 30 respectively (subject to its maximum DECIMAL precision when materialized).

This is not a harmless display difference: changing the setting is expected to control how many division digits survive, and persisted expression schemas inherit the result metadata.

Expected Behavior

div_precision_increment should participate in exact DECIMAL division type derivation and evaluation as it does in MySQL. Changing the session value should change the quotient scale and derived CTAS/view metadata for subsequent statements.

If MatrixOne does not intend to support the setting, it should not expose it as a writable dynamic compatibility variable whose accepted value is silently ignored.

Steps to Reproduce

DROP DATABASE IF EXISTS div_precision_repro;
CREATE DATABASE div_precision_repro;
USE div_precision_repro;

SET SESSION div_precision_increment=0;
SELECT @@session.div_precision_increment;
SELECT CAST(
  CAST(1 AS DECIMAL(10,2)) / CAST(3 AS DECIMAL(10,2))
  AS CHAR
);
CREATE TABLE d0 AS
SELECT CAST(1 AS DECIMAL(10,2)) / CAST(3 AS DECIMAL(10,2)) AS q;
SHOW CREATE TABLE d0;

SET SESSION div_precision_increment=4;
SELECT @@session.div_precision_increment;
SELECT CAST(
  CAST(1 AS DECIMAL(10,2)) / CAST(3 AS DECIMAL(10,2))
  AS CHAR
);
CREATE TABLE d4 AS
SELECT CAST(1 AS DECIMAL(10,2)) / CAST(3 AS DECIMAL(10,2)) AS q;
SHOW CREATE TABLE d4;

SET SESSION div_precision_increment=10;
SELECT CAST(
  CAST(1 AS DECIMAL(10,2)) / CAST(3 AS DECIMAL(10,2))
  AS CHAR
);

SET SESSION div_precision_increment=30;
SELECT CAST(
  CAST(1 AS DECIMAL(10,2)) / CAST(3 AS DECIMAL(10,2))
  AS CHAR
);

Additional information

pkg/frontend/variables.go registers div_precision_increment as a dynamic ScopeBoth integer variable with MySQL's default value 4. No other production code references the variable. The / DECIMAL return-type logic in pkg/sql/plan/function/list_operator.go instead derives a fixed scale around 12 from operand scales, so session state cannot influence either the result type or evaluator.

Decimal128 and Decimal256 operands, values 0/4/10/30, direct SELECT, CTAS and information-schema metadata were reproduced three times on the same latest-main build. No existing issue for div_precision_increment or this DECIMAL division behavior was found.

Activity

  1. added this to the MO-202609 milestone on Sep 10, 2026
  2. added theissue type on Sep 10, 2026
  3. added a commit that references this issue on Sep 26, 2026
    b457977
  4. Ariznawlll commented on Sep 27, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 部署方式:本地单机(1 CN / 1 TN / 1 LogService)
    • 测试日期:2026-09-27

    原问题验证

    在上述最新 main 上按 issue 原始复现步骤执行,并独立重复 3 次;3/3 均满足修复后的预期。当前 main 已包含修复提交 b457977980137e5056be18f03b22da6fc31908e0。

    Happy Path 覆盖

    1. div_precision_increment=0/4/10/30 时 DECIMAL 除法分别产生不同的有效 scale。

    Unhappy Path 覆盖

    1. 连续修改 session 变量后读取值与结果同步变化,未再静默忽略设置。

    白盒验证

    确认修复提交 b457977980137e5056be18f03b22da6fc31908e0 是当前 main 的祖先,并核对对应 MatrixOne BVT/实现路径;本次另以公开 SQL 协议执行黑盒验收。

    回归测试

    已加入 MOTR PR #204 的 issue_28295_28594_29085_29185_compatibility.test,MOTR 提交 2b4462f2;本地基线比对连续 3 次通过。

    测试证据

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions