Skip to content

[Compatibility]: ROLLUP returns an all-rolled row for empty input unlike MySQL #30148

Closed

Description

@Ariznawlll

Difference

For a grouped ROLLUP query whose input has no rows, MatrixOne returns the all-rolled aggregate identity row, while MySQL 8.0.46 returns an empty result set. This is reported as a MySQL compatibility difference for product/contract clarification, not as a claim that MatrixOne's grouping-set implementation is internally incorrect.

Reproduction

CREATE TABLE empty_rollup_probe(k INT, v INT);

SELECT k, SUM(v), COUNT(*), GROUPING(k)
FROM empty_rollup_probe
GROUP BY k WITH ROLLUP;

No rows are inserted.

Observed results

  • MatrixOne at official main commit 2ce4e58af6f03b943ee288ffad81012766cf830a, local single-CN topology: one row (NULL, NULL, 0, 1).
  • MySQL 8.0.46: zero rows.

The same difference is stable for an explicit WHERE 1=0, and when the empty input is read through a plain CTE, derived table, or ROLLUP CTE; each shape was repeated five times. This is not specific to remote merge-group transport or shared-CTE panic.

Compatibility context

Requested clarification

Please decide and document the intended behavior for ROLLUP over empty input. If MySQL compatibility is required, the current extra row is observable result-set incompatibility; if the all-rolled identity row is intentional standard behavior, record that exception in the compatibility contract so it is not reported as an implementation bug.

Activity

  1. added
    kind/bug
    on Oct 14, 2026
  2. added
    kind/compatibility
    on Oct 14, 2026
  3. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充写入与过滤边界:同一空表 empty_rollup_src(k INT,v INT) 上,以下查询在 MO 三次均产生 (NULL,NULL,0,1),MySQL 8.0.46 三次均为空集:

    SELECT k, SUM(v), COUNT(*), GROUPING(k)
    FROM empty_rollup_src
    GROUP BY k WITH ROLLUP
    HAVING COUNT(*) = 0;
    
    SELECT k, SUM(v), COUNT(*), GROUPING(k)
    FROM empty_rollup_src
    GROUP BY k WITH ROLLUP
    UNION ALL
    SELECT 99, 99, 99, 0;

    因此这个结果差异也会改变 HAVING 与 UNION ALL 的可见结果。写入路径同样可持久化该行:CREATE TABLE copied AS <ROLLUP query> 后 MO 表中有 1 行,MySQL 为 0 行;向预建表执行 INSERT ... SELECT <ROLLUP query>,每轮先清空目标表再执行,MO 插入 1 行、MySQL 插入 0 行,均重复 3 次。该描述仍是 MySQL 兼容性差异,不据此称现有表数据被意外篡改;目标表行来自该 SELECT 的实际结果。

  4. iamlinjunhong commented on Oct 14, 2026

    @iamlinjunhong
    Contributor

    The requested product-contract decision is to align grouped ROLLUP over empty input with MySQL: GROUP BY ... WITH ROLLUP should return zero rows rather than the all-rolled aggregate identity row.

    I will implement the correction with regression coverage for the reported SELECT/CTE/filter/write paths and controls for nonempty ROLLUP and ordinary ungrouped aggregation. The existing explicit empty grouping-set contract will be checked separately so this change is scoped to the MySQL-compatible ROLLUP behavior. The reporter should verify the result after the PR is merged.

  5. iamlinjunhong commented on Oct 14, 2026

    @iamlinjunhong
    Contributor

    The MySQL-alignment correction is proposed in #30169. Empty-input grouped ROLLUP now returns zero rows, while scalar aggregates, explicit GROUPING SETS/CUBE and real NULL input retain their existing identities/results.

    The regression reproduces the extra row against the original implementation. The full planner package, public SQL and forced remote regression, prepared reuse, optimization rollback, incremental static checks, and the SQL BVT (24/24 twice with zero database residue) pass locally.

    Please keep this issue open for the reporter to verify after the PR is merged.

  6. added
    ai-easy
    on Oct 15, 2026
  7. slyunnn commented on Oct 21, 2026

    @slyunnn

    Regression and extended verification for #30148 (2026-10-21)

    Verification Environment

    • MatrixOne source and running binary: latest local origin/main, commit a648b13e53cf0a07ff19211203a69e37b2d1dd93, titled feat(plan): add opt-in derived view query planning (#30551). The running mo-service -version reports Go 1.27.1, Linux/arm64, commit a648b13e53.
    • Full topology: 2 CN / 1 TN / 1 Log service / Proxy.
    • Test endpoints and connectivity:
      • Proxy: local port 6792 mapped to service port 6001 — connected.
      • CN1: local port 16893 mapped to service port 16001 — connected.
      • CN2: local port 16894 mapped to service port 16002 — connected.
    • Client/protocol: MySQL CLI 9.7.1 over TCP using the MySQL wire protocol. The MatrixOne regression SQL ran through Proxy; CN1 and CN2 were used for connectivity/version checks only. A separate temporary MySQL Community Server 8.0.46 was used as the compatibility control.

    What Was Covered

    • OK — Replayed the original empty-table query, SELECT k, SUM(v), COUNT(*), GROUPING(k) FROM empty_rollup_probe GROUP BY k WITH ROLLUP; MatrixOne returned zero rows.
    • OK — Empty-input variants using WHERE 1=0, a plain CTE, a derived table, a ROLLUP CTE, and the GROUP BY ROLLUP(k) spelling returned zero rows.
    • OK — HAVING COUNT(*) = 0 did not expose an all-rolled row. The UNION ALL case returned only its explicit sentinel row.
    • OK — Write consumers preserved the zero-row result: CTAS created a table with zero rows, and INSERT ... SELECT inserted zero rows.
    • OK — MySQL 8.0.46 returned the same empty-input result for the original query and the tested filter/CTE/derived/HAVING/UNION/write cases.
    • OK — Nonempty control with two input rows, including a real NULL grouping key, retained both detail groups and the all-rolled total in MatrixOne and MySQL. Row ordering differed, so the comparison is by result rows, not order.
    • OK — Empty-input scalar aggregation retained its identity row (NULL, 0, NULL).
    • OK — MatrixOne's explicit GROUPING SETS and CUBE controls retained their empty grouping-set identity row; these are intentionally outside the requested ROLLUP-to-MySQL alignment.
    • Not covered — The MatrixOne regression SQL was not executed directly through CN1 or CN2; those endpoints were connectivity-checked only.
    • Not covered — Window/SAMPLE cases, prepared-statement reuse, optimizer rollback internals, and a fresh SQL BVT run were not part of this direct verification.
    • Large-data regression: not needed. The behavior depends on whether the grouped input is empty, not on volume, block/batch boundaries, memory, spill, or concurrency; empty input and a minimal two-row control exercise the relevant boundary.

    Findings

    The merged correction is present in the tested latest origin/main. The original extra all-rolled row is absent for grouped ROLLUP over empty input, including the tested query-consumer paths, while scalar aggregation, explicit grouping-set identities, and nonempty input remain intact.

    Related fix: PR #30169, fix(sql): match MySQL empty-input ROLLUP results, merged as 2ba91f70e41d231fc7748f0a5b873fbff8da4d62. The PR's description reports function BVT 34/34 twice and window BVT 230/230 twice; those suites were not rerun as part of this verification.

    MOTR / BVT Coverage

    No MOTR test was added, recorded, or replayed. Direct SQL regression and compatibility comparison were executed against the live latest-main MatrixOne topology and MySQL 8.0.46. No fresh BVT pass is claimed; see the PR-reported BVT results above.

    Final Conclusion

    Fixed on the tested latest main for empty-input grouped ROLLUP. As requested in PR #30169, this issue is left open for the reporter to verify after merge.

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

Metadata

Metadata

Assignees

Labels

ai-easyarea/compatibilitykind/bugkind/compatibility

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions