[MDEV-19678] Unknown Column in 'having clause' on qualified access Created: 2019-06-03  Updated: 2022-11-29

Status: Confirmed
Project: MariaDB Server
Component/s: Parser
Affects Version/s: 5.5, 10.1, 10.4.5, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10
Fix Version/s: 10.4

Type: Bug Priority: Major
Reporter: - Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 0
Labels: parser, sql, upstream-fixed
Environment:

MariaDB 10.4.5-bionic in Docker on Ubuntu 19.04



 Description   

When I execute the following Code, I get the error message "Unknown column 'B.AJ' in 'having clause'". I expect that the column can be found (like in the GROUP BY clause or in the examples below) and the sql query can be executed properly.

CREATE SCHEMA A ;
 
CREATE  TABLE A.B  (AJ INTEGER) ;
 
-- Unknown column 'B.AJ' in 'having clause
SELECT  1 AS A FROM A.B CROSS JOIN A.B AS C GROUP BY B.AJ, C.AJ HAVING B.AJ < C.AJ;

If I delete the HAVING clause completely, the statement gets executed, so it knows the column name in the group by clause.

-- No Error
SELECT  1 AS A FROM A.B CROSS JOIN A.B AS C GROUP BY B.AJ, C.AJ;

Additionally, If I use SUM(B.AJ) (and SUM(C.AJ)) instead, everything works fine and the query can be executed.

-- No Error
SELECT  1 AS A FROM A.B CROSS JOIN A.B AS C GROUP BY B.AJ, C.AJ HAVING SUM(B.AJ) < SUM(C.AJ);

If I use the exact same condition in a WHERE clause, it also works properly:

-- No Error
SELECT  1 AS A FROM A.B CROSS JOIN A.B AS C WHERE B.AJ < C.AJ GROUP BY B.AJ, C.AJ ;



 Comments   
Comment by Elena Stepanova [ 2019-06-03 ]

Reproducible on all of MariaDB 5.5-10.4 and MySQL 5.6.
Not reproducible on MySQL 5.7.

Generated at Thu Feb 08 08:53:31 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.