Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Critical
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.2, 10.11.14, 12.1.2
-
12.1.2-MariaDB-ubu2404
Description
The server returns an incorrect Empty Set under specific conditions involving GROUP BY, aliases, and a HAVING clause with IS NOT TRUE.
Specifically, if a derived table selects the same underlying column twice with different aliases (e.g., c1 AS ca1, c1 AS ca2), and the outer query selects ca1 but groups by ca2, the optimizer incorrectly filters out NULL values that satisfy the HAVING condition.
If the SELECT list and GROUP BY clause use the same alias, the query returns the correct result.
CREATE TABLE t1(c1 TEXT); |
INSERT INTO t1 (c1) VALUES (NULL), ('abc'); |
|
|
mysql> SELECT ca1 FROM (SELECT c1 AS ca1, c1 AS ca2 FROM t1) AS ta1 GROUP BY ca2 HAVING (ca2 = ANY (SELECT c1 FROM t1))IS NOT TRUE; |
Empty set (0.002 sec) |
|
|
mysql> SELECT ca2 FROM (SELECT c1 AS ca1, c1 AS ca2 FROM t1) AS ta1 GROUP BY ca2 HAVING (ca2 = ANY (SELECT c1 FROM t1))IS NOT TRUE; |
+------+ |
| ca2 |
|
+------+ |
| NULL | |
+------+ |
1 row in set (0.003 sec) |
Attachments
Issue Links
- is caused by
-
MDEV-29300 Assertion `*ref && (*ref)->fixed()' failed in Item_field::fix_outer_field on SELECT
-
- Closed
-
- is part of
-
MDEV-38476 Wrong Result (Empty Set) with derived_merge=on using AVG() on text column in HAVING clause
-
- In Progress
-
- relates to
-
MDEV-38476 Wrong Result (Empty Set) with derived_merge=on using AVG() on text column in HAVING clause
-
- In Progress
-