1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Bug #31794: no syntax error on SELECT id FROM t HAVING count(*)>2

The HAVING clause is subject to the same rules as the SELECT list
about using aggregated and non-aggregated columns.
But this was not enforced when processing implicit grouping from
using aggregate functions.
Fixed by performing the same checks for HAVING as for SELECT.
This commit is contained in:
gkodinov/kgeorge@magare.gmz
2007-11-01 18:36:24 +02:00
parent f370e4b3d4
commit 92a5605d43
3 changed files with 44 additions and 2 deletions

View File

@ -565,11 +565,12 @@ JOIN::prepare(Item ***rref_pointer_array,
/*
Check if one one uses a not constant column with group functions
and no GROUP BY.
Check if there are references to un-aggregated columns when computing
aggregate functions with implicit grouping (there is no GROUP BY).
TODO: Add check of calculation of GROUP functions and fields:
SELECT COUNT(*)+table.col1 from table1;
*/
if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY)
{
if (!group_list)
{
@ -583,6 +584,13 @@ JOIN::prepare(Item ***rref_pointer_array,
else if (!(flag & 2) && !item->const_during_execution())
flag|=2;
}
if (having)
{
if (having->with_sum_func)
flag |= 1;
else if (!having->const_during_execution())
flag |= 2;
}
if (flag == 3)
{
my_message(ER_MIX_OF_GROUP_FUNC_AND_FIELDS,