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.