mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
Fixed bug MDEV-14368 Improper error for a grouping query that
uses alias in HAVING when sql_mode = 'ONLY_FULL_GROUP_BY'
This patch corrects the patch for bug#18739: non-standard
HAVING extension was allowed in strict ANSI sql mode
added in 2006 by commit 4b7c4cd27f.
As a result of incompleteness of the fix in the above commit
if a query with GROUP BY contained an aggregate function with an
alias and this alias was used in the HAVING clause of the query
the server reported an error when sql_mode was set to
'ONLY_FULL_GROUP_BY'.
This commit is contained in:
@@ -697,3 +697,18 @@ id column_1
|
||||
1 80a12660d24a72460e5e292fe33f870276d7f40a
|
||||
expected -- 1 row(s) returned not ER_BAD_FIELD_ERROR
|
||||
drop table t1;
|
||||
#
|
||||
# mdev-14368: grouping query with alias for aggregate function in HAVING
|
||||
# when sql_mode = 'ONLY_FULL_GROUP_BY'
|
||||
set @save_sql_mode= @@sql_mode;
|
||||
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;
|
||||
a ct
|
||||
1 2
|
||||
2 1
|
||||
3 1
|
||||
4 2
|
||||
set sql_mode=@save_sql_mode;
|
||||
drop table t1;
|
||||
|
||||
@@ -727,3 +727,20 @@ HAVING UPPER(`column_1`) LIKE '8%';
|
||||
--echo expected -- 1 row(s) returned not ER_BAD_FIELD_ERROR
|
||||
|
||||
drop table t1;
|
||||
|
||||
--echo #
|
||||
--echo # mdev-14368: grouping query with alias for aggregate function in HAVING
|
||||
--echo # when sql_mode = 'ONLY_FULL_GROUP_BY'
|
||||
|
||||
|
||||
set @save_sql_mode= @@sql_mode;
|
||||
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;
|
||||
|
||||
set sql_mode=@save_sql_mode;
|
||||
|
||||
drop table t1;
|
||||
|
||||
@@ -4771,7 +4771,8 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select)
|
||||
|
||||
if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
|
||||
select->having_fix_field &&
|
||||
select_ref != not_found_item && !group_by_ref)
|
||||
select_ref != not_found_item && !group_by_ref &&
|
||||
!ref->alias_name_used)
|
||||
{
|
||||
/*
|
||||
Report the error if fields was found only in the SELECT item list and
|
||||
|
||||
Reference in New Issue
Block a user