Skip to content

[Bug]: SUM() over INT columns reports BIGINT instead of DECIMAL(32,0) in metadata #30792

Closed as not planned

Description

@Ariznawlll

Description

SUM() over the INT family (TINYINT/SMALLINT/MEDIUMINT/INT) reports its result column as BIGINT in protocol metadata and information_schema, while MySQL 8.0 reports DECIMAL(32,0). The runtime values are exact on both sides (verified, including sums that exceed INT64 — MatrixOne correctly returns full-precision DECIMAL values there), so this is a result-type/metadata divergence, but it breaks type-sensitive consumers: MySQL protocol clients (JDBC/ORM/C connectors) choose their accessor from the declared column type, and BIGINT declarations route SUM results into 64-bit accessors that cannot represent the values the aggregate can actually produce.

MySQL promotes SUM(int-family) to DECIMAL precisely because the sum of ~4.3 billion INT rows at max value is ~9.2e18, which overflows BIGINT. A SUM(int_col) on a large table can genuinely exceed INT64 — and MatrixOne's engine can produce that exact value (it already computes in a wider domain), while simultaneously telling the client the column is BIGINT.

Environment

  • MatrixOne dev build 3a1e42b430, server reports 8.0.30-MatrixOne-v1.3.0
  • MySQL comparison: 8.0.45 (localhost), same fixtures

Reproduction

CREATE TABLE ti (i INT, dc DECIMAL(10,2));
INSERT INTO ti VALUES (1, 1.55), (2, 2.55);

CREATE OR REPLACE VIEW vti AS SELECT SUM(i) si, SUM(dc) sdc, AVG(i) ai FROM ti;
SELECT column_name, data_type, numeric_precision, numeric_scale
FROM information_schema.columns WHERE table_name='vti' ORDER BY ordinal_position;

MatrixOne:

si   bigint    19  0      ← wrong type family for SUM(INT)
sdc  decimal   32  2      ✓
ai   decimal   14  4      ✓

MySQL 8.0.45:

si   decimal   32  0      ← DECIMAL per MySQL aggregate result rules
sdc  decimal   32  2      ✓
ai   decimal   14  4      ✓

SUM(BIGINT) is already reported as DECIMAL on MatrixOne (decimal(38,0) vs MySQL's decimal(41,0) — precision width differs but the type family is right), so this report is only about the INT-family SUM declaration.

Value-domain proof that the BIGINT declaration is unsafe (values computed correctly on MatrixOne — the declaration is what's wrong):

CREATE TABLE big_sum (v BIGINT);
INSERT INTO big_sum SELECT 9223372036854775807 FROM generate_series(1, 3000) g;
SELECT SUM(v) FROM big_sum;
-- MatrixOne: 27670116110564327421*1000-scale exact value returned: 27670116110564327421000 (full precision, correct)

The engine already produces > INT64 sums exactly; the declared BIGINT type contradicts the engine's own value domain. For the INT input family the same overflow is reachable at realistic table sizes (~4.3e9 rows of INT at max), and any JDBC getLong() on such a SUM throws Value '...' is outside of valid range for java.lang.Long where MySQL-server clients receive a DECIMAL column and call getBigDecimal() successfully.

Impact

  • ORM schema introspection (Django DecimalField vs BigIntegerField) and report generators that branch on DATA_TYPE mis-handle SUM columns.
  • JDBC getObject/getLong accessors selected by declared type are lossy for large-table SUMs that the engine itself computes exactly.
  • Related closed issue [Bug]: AVG and SUM overflow on BIGINT UNSIGNED values larger than uint64 accumulator #25485 fixed the value overflow; this is the residual result-type declaration divergence not covered there (that issue covered BIGINT-UNSIGNED value overflow, not the INT-family result type contract).

Root-cause pointer

The INT-family aggregation return type is chosen as int64 (bigint) in the aggregate type-inference path, while the bigint input family already widens to decimal. The same widening rule needs to apply to int8/int16/int32/int64 uniformly (MySQL sums the whole INT family in DECIMAL).

Activity

  1. added
    kind/bug
    on Oct 22, 2026
  2. added this to the MO-202611 milestone on Oct 22, 2026
  3. changed the title [-][Bug]: SUM() over the INT family reports BIGINT result type instead of MySQL's DECIMAL(32,0) — wrong type family in protocol metadata and information_schema[/-] [+][Bug]: SUM() over INT columns reports BIGINT instead of DECIMAL(32,0) in metadata[/+] on Oct 22, 2026
  4. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    This report is now tracked together with #28230. The canonical issue retains explicit acceptance cases for the behavior described here. This is an administrative duplicate/consolidation closure only; the underlying defect is not claimed fixed. The original description and discussion remain available on this issue.

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions