diff options
author | unknown <timour@mysql.com> | 2005-06-15 10:12:49 +0300 |
---|---|---|
committer | unknown <timour@mysql.com> | 2005-06-15 10:12:49 +0300 |
commit | 476ca52ee7c0cb1bdee081fba4260d9aff39f5dc (patch) | |
tree | a5b3fda1a95fe8aecc8494d6133d874182c1f90d /mysql-test/r | |
parent | 894fd6ae07466eca193819295bd8332e5fd572c9 (diff) | |
download | mariadb-git-476ca52ee7c0cb1bdee081fba4260d9aff39f5dc.tar.gz |
Fix for BUG#11211 "GROUP BY doesn't work correctly"
When the GROUP BY clause contains a column reference that can be resolved to
both an aliased column in the SELECT list, and to a column in the FROM clause,
the group column is resolved to the column in the FROM clause (for ANSI conformance).
However, it may be so that the user's intent is just the other way around, and he/she
gets the query results grouped by a completely different column than expexted.
This patch adds a warning in such cases that tells the user that there is potential
ambiguity in the group column.
sql/sql_select.cc
- Added a warning when a GROUP column is ambiguous due to that there is a
column reference with the same name both in the SELECT and FROM clauses.
In this case we resolve to the column in FROM clause and warn the user
of a possible ambiguity.
- More extensive comments.
- Changed the function to return bool instead of int (as in other places).
mysql-test/t/group_by.test
Added test for BUG#11211.
mysql-test/r/group_by.result
Added test for BUG#11211.
mysql-test/r/group_by.result:
Import patch 11211.diff
mysql-test/t/group_by.test:
Import patch 11211.diff
sql/sql_select.cc:
Import patch 11211.diff
BitKeeper/etc/ignore:
Added ndb/src/dummy.cpp to the ignore list
mysql-test/r/alias.result:
Added warning for potentially ambiguous column.
mysql-test/r/having.result:
Added warning for potentially ambiguous column.
Diffstat (limited to 'mysql-test/r')
-rw-r--r-- | mysql-test/r/alias.result | 2 | ||||
-rw-r--r-- | mysql-test/r/group_by.result | 24 | ||||
-rw-r--r-- | mysql-test/r/having.result | 1 |
3 files changed, 27 insertions, 0 deletions
diff --git a/mysql-test/r/alias.result b/mysql-test/r/alias.result index 587c21e9129..395f49f3635 100644 --- a/mysql-test/r/alias.result +++ b/mysql-test/r/alias.result @@ -58,6 +58,8 @@ INSERT INTO t1 VALUES (3359362,406,3359362,'Mustermann Musterfrau',7001,'2000-05 SELECT ELT(FIELD(kundentyp,'PP','PPA','PG','PGA','FK','FKA','FP','FPA','K','KA','V','VA',''), 'Privat (Private Nutzung)','Privat (Private Nutzung) Sitz im Ausland','Privat (geschaeftliche Nutzung)','Privat (geschaeftliche Nutzung) Sitz im Ausland','Firma (Kapitalgesellschaft)','Firma (Kapitalgesellschaft) Sitz im Ausland','Firma (Personengesellschaft)','Firma (Personengesellschaft) Sitz im Ausland','oeff. rechtl. Koerperschaft','oeff. rechtl. Koerperschaft Sitz im Ausland','Eingetragener Verein','Eingetragener Verein Sitz im Ausland','Typ unbekannt') AS Kundentyp ,kategorie FROM t1 WHERE hdl_nr < 2000000 AND kategorie IN ('Prepaid','Mobilfunk') AND st_klasse = 'Workflow' GROUP BY kundentyp ORDER BY kategorie; Kundentyp kategorie Privat (Private Nutzung) Mobilfunk +Warnings: +Warning 1052 Column 'kundentyp' in group statement is ambiguous drop table t1; CREATE TABLE t1 ( AUFNR varchar(12) NOT NULL default '', diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 937ed401f40..7b97f998fe5 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -722,3 +722,27 @@ WHERE hostname LIKE '%aol%' GROUP BY hostname; hostname no cache-dtc-af05.proxy.aol.com 1 +drop table if exists t1, t2; +Warnings: +Note 1051 Unknown table 't2' +create table t1 (c1 char(3), c2 char(3)); +create table t2 (c3 char(3), c4 char(3)); +insert into t1 values ('aaa', 'bb1'), ('aaa', 'bb2'); +insert into t2 values ('aaa', 'bb1'), ('aaa', 'bb2'); +select t1.c1 as c2 from t1, t2 where t1.c2 = t2.c4 +group by c2; +c2 +aaa +aaa +Warnings: +Warning 1052 Column 'c2' in group statement is ambiguous +show warnings; +Level Code Message +Warning 1052 Column 'c2' in group statement is ambiguous +select t1.c1 as c2 from t1, t2 where t1.c2 = t2.c4 +group by t1.c1; +c2 +aaa +show warnings; +Level Code Message +drop table t1, t2; diff --git a/mysql-test/r/having.result b/mysql-test/r/having.result index 86c9adf8cf6..35a1358dd0c 100644 --- a/mysql-test/r/having.result +++ b/mysql-test/r/having.result @@ -304,6 +304,7 @@ s1 0 0 Warnings: +Warning 1052 Column 's1' in group statement is ambiguous Warning 1052 Column 's1' in having clause is ambiguous select s1*0 from t1 group by s1 having s1 = 0; s1*0 |