Skip to content

Commit 05b678b

Browse files
committed
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.
1 parent c83d6ff commit 05b678b

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

mysql-test/r/group_by.result

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,3 +2545,8 @@ select
25452545
from t4;
25462546
ERROR 42S22: Reference 'field7' not supported (reference to group function)
25472547
drop table t1, t2, t3, t4;
2548+
create table t1 (c1 int, c2 int);
2549+
create table t2 (c1 int, c2 int);
2550+
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;
2551+
c1 c1
2552+
drop table t1, t2;

mysql-test/t/group_by.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,14 @@ select
17221722
from t4;
17231723
drop table t1, t2, t3, t4;
17241724

1725+
#
1726+
# MDEV-12489 The select stmt may fail due to "having clause is ambiguous" unexpected
1727+
#
1728+
create table t1 (c1 int, c2 int);
1729+
create table t2 (c1 int, c2 int);
1730+
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;
1731+
drop table t1, t2;
1732+
17251733
#
17261734
# End of MariaDB 5.5 tests
17271735
#

sql/item.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4622,7 +4622,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
46224622
int cur_match_degree= 0;
46234623

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

0 commit comments

Comments
 (0)