Skip to content

[Bug]: Integer overflow in SELECT and SUM silently wraps around instead of throwing error #22734

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main, 3.0-dev

Commit ID

latest

Other Environment Information

- Hardware parameters:
- OS type:
- Others:

Actual Behavior

MatrixOne currently allows integer overflow in SELECT arithmetic expressions and SUM aggregate functions to silently wrap around, returning incorrect results instead of throwing an error. This is a critical data correctness issue that violates SQL standards and differs from all major databases (MySQL, PostgreSQL, Oracle, SQL Server).

Example 1: SELECT Arithmetic Overflow

-- Current behavior (WRONG)
SELECT 9223372036854775807 + 1;
-- Returns: -9223372036854775808  ❌ (wraps to MIN_BIGINT)

-- Expected behavior (MySQL 8.0 / PostgreSQL)
SELECT 9223372036854775807 + 1;
-- ERROR 1690 (22003): BIGINT value is out of range

Example 2: Multiplication Overflow

-- Current behavior (WRONG)
SELECT 9223372036854775807 * 2;
-- Returns: -2  ❌ (completely wrong!)

-- Expected behavior
-- ERROR: BIGINT value is out of range

Example 3: SUM Aggregate Overflow

-- Current behavior (WRONG)
CREATE TABLE t (val BIGINT);
INSERT INTO t VALUES (9223372036854775807), (9223372036854775807), (9223372036854775807);
SELECT SUM(val) FROM t;
-- Returns: 9223372036854775805 or -2  ❌ (wrong result)

-- Expected behavior
-- ERROR: BIGINT value is out of range in aggregate SUM

Impact

Severity: CRITICAL (P0)

This issue can cause:

  • ✅ Data corruption in financial calculations
  • ✅ Silent data errors that are hard to detect
  • ✅ Security vulnerabilities (integer overflow exploits)
  • ✅ Audit failures in regulated industries
  • ✅ Incorrect analytics and reporting

Expected Behavior

No response

Steps to Reproduce

As above

Additional information

No response

Activity

  1. added this to the MO-202511 milestone on Oct 31, 2025
  2. self-assigned this
    on Oct 31, 2025
  3. added theissue type on Oct 31, 2025
  4. added
    kind/bug
    severity/s0
    on Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions