Skip to content

[Bug]: Sql select query get "Division by zero" error #23404

Closed

Description

@ytw1005

Is there an existing issue for the same bug?

Branch Name

main

Commit ID

d59cab2

Other Environment Information

- Hardware parameters:
- OS type:
- Others:

Actual Behavior

使用MO数据库时会有division by zero报错, 但是mysql不会。
MO:

Image

mysql:

Image

Expected Behavior

No response

Steps to Reproduce

CREATE TABLE test_div_zero (
    a INT,
    b INT
);

INSERT INTO test_div_zero (a, b) VALUES
(100, 0),
(200, 0),
(300, 0);

SELECT
    SUM(a)            AS sum_a,
    SUM(b)            AS sum_b,
    SUM(a)/SUM(b)                       AS raw_ratio,        -- 原始写法,得 NULL
    COALESCE(SUM(a) / NULLIF(SUM(b),0), 0) AS safe_ratio      -- 安全写法,得 0
FROM test_div_zero;

Additional information

No response

Activity

  1. added
    kind/bug
    on Dec 30, 2025
  2. added
    priority/p0
    kind/compatibility
    and removed on Jan 4, 2026
  3. added theissue type on Jan 4, 2026
  4. added this to the MO-202601 milestone on Jan 4, 2026
  5. assigned and unassigned on Jan 7, 2026
  6. XuPeng-SH commented on Jan 7, 2026

    @XuPeng-SH
    Contributor

    @heni02 fixed

  7. ghost closed this as completedon Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugkind/compatibilitypriority/p0

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions