Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Duplicate
-
12.3.1
-
ubuntu22.04
-
Not for Release Notes
Description
Summary
In GROUP BY ... WITH ROLLUP, grouping columns must be NULL in the super-aggregate (grand total) row. MariaDB nullifies only the first select-list slot tied to the GROUP BY column. Any additional bare reference to the same column — duplicate column, alias (a AS c2), or extra slot from t.* expansion — keeps the last processed group's value in the super-aggregate row.
Wrapping the duplicate in an expression (a + 0) yields the correct NULL. Reproduced on MariaDB 12.3.1-MariaDB-asan-log. MySQL 9.6 returns NULL for both columns in the super-aggregate row.
Minimal Reproducer
DROP TABLE IF EXISTS t1; |
CREATE TABLE t1 (a INT) ENGINE=InnoDB; |
INSERT INTO t1 VALUES (10), (20), (30); |
|
|
SELECT a, a AS c2 |
FROM t1 |
GROUP BY a WITH ROLLUP; |
Actual Result (MariaDB 12.3.1-MariaDB-asan-log)
+------+------+
|
| a | c2 |
|
+------+------+
|
| 10 | 10 |
|
| 20 | 20 |
|
| 30 | 30 |
|
| NULL | 30 | <-- wrong: c2 should be NULL
|
+------+------+
|
Expected Result
Super-aggregate row: NULL | NULL (both grouping-column projections NULL), consistent with MySQL 9.6 and SQL ROLLUP semantics.
Root Cause (Hypothesis)
ROLLUP nullification applies to one select-list item per GROUP BY expression (bound during resolution). Additional bare Item_field nodes referencing the same physical column are not rewritten and still read the row buffer populated with the last group's value. Expression wrappers (a+0) force evaluation on the already-nullified value.
Likely fix: ensure all select-list references mapping to grouping items are nullified, not only the first per group expression.
Environment
| Item | Value |
|---|---|
| Version | 12.3.1-MariaDB-asan-log |
| Revision | 21a0714a118614982d20bfa504763d7247800091 |
| OS | Linux x86_64 (RHEL 8.10 kernel 4.18) |
| MySQL control | 9.6.0 — super-aggregate NULL, NULL |
Suggested Regression Test
CREATE TABLE t1 (a INT); |
INSERT INTO t1 VALUES (10),(20),(30); |
SELECT a, a AS c2 FROM t1 GROUP BY a WITH ROLLUP; |
-- last row must be: NULL NULL
|
DROP TABLE t1; |
Attachments
Issue Links
- duplicates
-
MDEV-19039 Wrong result from query, using window function and GROUP BY .. WITH ROLLUP
-
- Stalled
-