Repository navigation
Description
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
maincommit2ce4e58af6f03b943ee288ffad81012766cf830a, 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
- The mysql-compatibility-contract README currently does not record this empty-input ROLLUP behavior.
- [Bug]: ROLLUP merge-group emits synthetic empty NULL groups and corrupts GROUPING()/aggregates #29096 concerned synthetic NULL rows caused by loss of grouping provenance across remote transport and is closed after fix(sql): preserve ROLLUP provenance across remote batch transport #29115. This report uses a direct, single-CN empty-input query and does not reopen that issue.
- fix(sql): preserve ROLLUP provenance across remote batch transport #29115 intentionally preserves empty grouping-set identities; the distributed
rollup.sqlregression also documents retaining an all-rolled row for runtime-empty grouping-set input. This report asks whether the resulting MySQL difference is an accepted MatrixOne contract or should be aligned with MySQL.
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
Ariznawlll commentedon Oct 14, 2026
补充写入与过滤边界:同一空表
empty_rollup_src(k INT,v INT)上,以下查询在 MO 三次均产生(NULL,NULL,0,1),MySQL 8.0.46 三次均为空集:因此这个结果差异也会改变 HAVING 与 UNION ALL 的可见结果。写入路径同样可持久化该行:
CREATE TABLE copied AS <ROLLUP query>后 MO 表中有 1 行,MySQL 为 0 行;向预建表执行INSERT ... SELECT <ROLLUP query>,每轮先清空目标表再执行,MO 插入 1 行、MySQL 插入 0 行,均重复 3 次。该描述仍是 MySQL 兼容性差异,不据此称现有表数据被意外篡改;目标表行来自该 SELECT 的实际结果。iamlinjunhong commentedon Oct 14, 2026
The requested product-contract decision is to align grouped
ROLLUPover empty input with MySQL:GROUP BY ... WITH ROLLUPshould 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.
iamlinjunhong commentedon Oct 14, 2026
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.
fix(sql): match MySQL empty-input ROLLUP results (#30169)
slyunnn commentedon Oct 21, 2026
Regression and extended verification for #30148 (2026-10-21)
Verification Environment
origin/main, commita648b13e53cf0a07ff19211203a69e37b2d1dd93, titledfeat(plan): add opt-in derived view query planning (#30551). The runningmo-service -versionreports Go1.27.1, Linux/arm64, commita648b13e53.2 CN / 1 TN / 1 Log service / Proxy.6792mapped to service port6001— connected.16893mapped to service port16001— connected.16894mapped to service port16002— connected.9.7.1over 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 Server8.0.46was used as the compatibility control.What Was Covered
SELECT k, SUM(v), COUNT(*), GROUPING(k) FROM empty_rollup_probe GROUP BY k WITH ROLLUP; MatrixOne returned zero rows.WHERE 1=0, a plain CTE, a derived table, a ROLLUP CTE, and theGROUP BY ROLLUP(k)spelling returned zero rows.HAVING COUNT(*) = 0did not expose an all-rolled row. TheUNION ALLcase returned only its explicit sentinel row.INSERT ... SELECTinserted zero rows.8.0.46returned the same empty-input result for the original query and the tested filter/CTE/derived/HAVING/UNION/write cases.NULLgrouping 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.(NULL, 0, NULL).GROUPING SETSandCUBEcontrols retained their empty grouping-set identity row; these are intentionally outside the requested ROLLUP-to-MySQL alignment.Findings
The merged correction is present in the tested latest
origin/main. The original extra all-rolled row is absent for groupedROLLUPover 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 as2ba91f70e41d231fc7748f0a5b873fbff8da4d62. The PR's description reports function BVT34/34twice and window BVT230/230twice; 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
mainfor empty-input groupedROLLUP. As requested in PR #30169, this issue is left open for the reporter to verify after merge.