Commit 05b678bc authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-12489 The select stmt may fail due to "having clause is ambiguous" unexpected

only compare field references with an alias (from the SELECT clause)
when this reference doesn't specify an explicit table name part.
parent c83d6ff8
......@@ -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))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment