Bug #121500 CTE omits a row from a GROUP BY WITH ROLLUP result
Submitted: 14 Oct 7:42
Reporter: jinxin gui Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:26.7.0 OS:Linux
Assigned to: CPU Architecture:Any
Tags: cte, rollup

[14 Oct 7:42] jinxin gui
Description:
Selecting directly from a GROUP BY ... WITH ROLLUP query returns two rows, but selecting from a CTE containing the same query returns only one. The CTE result is missing the row containing 7; only the NULL rollup row remains.

How to repeat:
Run the following in an empty schema:

CREATE TABLE t (f1 INT, pk INT NOT NULL, PRIMARY KEY (pk));
INSERT INTO t VALUES (7, 3);

SELECT f1 AS col1 FROM t WHERE pk = 3 GROUP BY f1 WITH ROLLUP ORDER BY f1;

WITH c AS (SELECT f1 AS col1 FROM t WHERE pk = 3 GROUP BY f1 WITH ROLLUP ORDER BY f1) SELECT col1 FROM c;

Actual result:

The first query returns two rows:

NULL
7

The second query returns only one row:

NULL

Expected result:

Both queries should return the same two rows, NULL and 7. Reading the query through a CTE should not remove the grouped row.