Skip to content
Permalink
Browse files
MDEV-12489 The select stmt may fail due to "having clause is ambiguou…
…s" unexpected

only compare field references with an alias (from the SELECT clause)
when this reference doesn't specify an explicit table name part.
  • Loading branch information
vuvova committed Jul 12, 2017
1 parent c83d6ff commit 05b678b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
@@ -2545,3 +2545,8 @@ select
from t4;
ERROR 42S22: Reference 'field7' not supported (reference to group function)
drop table t1, t2, t3, t4;
create table t1 (c1 int, c2 int);
create table t2 (c1 int, c2 int);
select t1.c1 as c1, t2.c2 as c1 from t1, t2 where t1.c1 < 20 and t2.c2 > 5 group by t1.c1, t2.c2 having t1.c1 < 3;
c1 c1
drop table t1, t2;
@@ -1722,6 +1722,14 @@ select
from t4;
drop table t1, t2, t3, t4;

#
# MDEV-12489 The select stmt may fail due to "having clause is ambiguous" unexpected
#
create table t1 (c1 int, c2 int);
create table t2 (c1 int, c2 int);
select t1.c1 as c1, t2.c2 as c1 from t1, t2 where t1.c1 < 20 and t2.c2 > 5 group by t1.c1, t2.c2 having t1.c1 < 3;
drop table t1, t2;

#
# End of MariaDB 5.5 tests
#
@@ -4622,7 +4622,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
int cur_match_degree= 0;

/* SELECT list element with explicit alias */
if ((*(cur_group->item))->name &&
if ((*(cur_group->item))->name && !table_name &&
!(*(cur_group->item))->is_autogenerated_name &&
!my_strcasecmp(system_charset_info,
(*(cur_group->item))->name, field_name))

0 comments on commit 05b678b

Please sign in to comment.