Bug #11553 gives error if aggregate user-defined function in HAVING clause
Submitted: 24 Jun 2005 19:24 Modified: 23 Sep 2005 16:59
Reporter: Bob Rintel Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: User-defined functions ( UDF ) Severity:S2 (Serious)
Version:5.0.7 OS:Linux (Linux)
Assigned to: Ramil Kalimullin CPU Architecture:Any

[24 Jun 2005 19:24] Bob Rintel
Description:
It says:

ERROR 1054 (42S22): Unknown column 'y' in 'having clause'

if you have an aggregate user-defined function in a HAVING clause.

See below for an actual mysql session demonstrating the problem.

How to repeat:
mysql> create aggregate function mysum returns integer soname 'mylib.so';
Query OK, 0 rows affected (0.00 sec)

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create temporary table t (x int, y int);
Query OK, 0 rows affected (0.00 sec)

mysql> insert t values (1, 2);
Query OK, 1 row affected (0.00 sec)

mysql> insert t values (1, 3);
Query OK, 1 row affected (0.00 sec)

mysql> insert t values (2, 4);
Query OK, 1 row affected (0.00 sec)

mysql> select x, mysum(y) from t group by x;
+------+-----------+
| x    | mysum(y) |
+------+-----------+
|    1 |         5 |
|    2 |         4 |
+------+-----------+
2 rows in set (0.00 sec)

mysql> select x, mysum(y) from t group by x having sum(y) < 9;
+------+-----------+
| x    | mysum(y) |
+------+-----------+
|    1 |         5 |
|    2 |         4 |
+------+-----------+
2 rows in set (0.00 sec)

mysql> select x, mysum(y) from t group by x having mysum(y) < 9;
ERROR 1054 (42S22): Unknown column 'y' in 'having clause'
mysql> quit
[7 Sep 2005 18:06] Serban Ghita
i am using MySQL 4.1.13 and i have the same problem with a query using HAVING, with functions CONCAT and LPAD
[10 Sep 2005 23:38] Hartmut Holzgraefe
verified with 4.0.25, 4.1.14, 5.0.10
[15 Sep 2005 14:07] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/29909
[20 Sep 2005 7:34] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/30086
[20 Sep 2005 8:02] Ramil Kalimullin
Please ignore my previous patch, it was committed accidentally.
[20 Sep 2005 8:14] Ramil Kalimullin
Please ignore my previous message :)
(the commit was premeditated).
[20 Sep 2005 9:29] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/30093
[22 Sep 2005 8:33] Ramil Kalimullin
fixed in 4.1.15 and 5.0.14
[23 Sep 2005 16:59] Paul DuBois
Noted in 4.1.15, 5.0.14 changelogs.