[MDEV-14368] Improper error for a grouping query that uses alias in HAVING when sql_mode = 'ONLY_FULL_GROUP_BY' Created: 2017-11-11  Updated: 2018-01-05  Resolved: 2017-11-14

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 5.5, 10.0, 10.1, 10.2, 10.3
Fix Version/s: 5.5.59

Type: Bug Priority: Major
Reporter: Igor Babaev Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: None


 Description   

If a query with GROUP BY contains an aggregate function with an alias and this alias
is used in the HAVING clause of the query the server reports an error:

MariaDB [test]> SELECT a, COUNT(a) as ct FROM t1 GROUP BY a HAVING ct>0;
ERROR 1463 (42000): Non-grouping field 'ct' is used in HAVING clause

The following test case demonstrates the problem:

SET  sql_mode = 'ONLY_FULL_GROUP_BY';
 
create table t1(a int);
insert  t1 values (4),(1),(2),(1), (3),(4);
 
SELECT a, COUNT(a) as ct FROM t1 GROUP BY a HAVING ct>0;



 Comments   
Comment by Igor Babaev [ 2017-11-14 ]

A fix for this bug was pushed into the 5.5 tree.

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