Bug #8775 | Using string literal with a name of a column makes query return too few rows | ||
---|---|---|---|
Submitted: | 24 Feb 2005 11:15 | Modified: | 14 Apr 2006 13:49 |
Reporter: | [ name withheld ] | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server | Severity: | S2 (Serious) |
Version: | 4.1.10 | OS: | Windows (windows/linux) |
Assigned to: | Georgi Kodinov | CPU Architecture: | Any |
[24 Feb 2005 11:15]
[ name withheld ]
[24 Feb 2005 11:16]
[ name withheld ]
sql scripts to populate DB to reproduce error
Attachment: mysqlbugDemo.zip (application/zip, text), 11.53 KiB.
[2 Mar 2005 12:46]
[ name withheld ]
not a bug in mysql-5.0.2-alpha-win
[9 Aug 2005 14:35]
Mark Matthews
Please retest to determine platform-specificness.
[12 Aug 2005 19:44]
NOT_FOUND NOT_FOUND
I installed the linux rpms for 4.1.13 and have a similar problem. create table test(t1 int, t2 int); insert into test values (1,1), (1,2); select DISTINCT t1, t2, 'a' from test; +------+------+---+ | t1 | t2 | a | +------+------+---+ | 1 | 1 | a | | 1 | 2 | a | +------+------+---+ -- missing a row here select DISTINCT t1, 'a', t2 from test; +------+---+------+ | t1 | a | t2 | +------+---+------+ | 1 | a | 1 | +------+---+------+
[13 Jan 2006 21:21]
Gunnar von Boehn
not a bug in 4.1.11-Debian_1-log |
[4 Apr 2006 22:35]
Hartmut Holzgraefe
test case
Attachment: bug8775.tar.gz (application/x-gzip, text), 873 bytes.
[4 Apr 2006 22:47]
Hartmut Holzgraefe
The 2nd incident is not reproduceable anymore with current 4.1 sources but the original issue reported is still there (tested on linux) i have attached a testcase for both failures
[14 Apr 2006 10:02]
Georgi Kodinov
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant product(s). This looks like a valid behavior taking into account the extensions to the standard SQL that MySQL implements. The query in question : select 'lit_val_col', lit_val_col from .... group by lit_val_col involves two components : 1. the fact that MySQL extends the meaning of the SQL standard by allowing referencing expression names from the select list not only into ORDER BY (as per the SQL standard) by also in GROUP BY and HAVING clauses. See section 13.2.7 (http://dev.mysql.com/doc/refman/4.1/en/select.html) : "A select_expr can be given an alias using AS alias_name. The alias is used as the expression's column name and can be used in GROUP BY, ORDER BY, or HAVING clauses)." 2. The 'lit_val_col' select expression (string literal) in the above statement has an implicit name of "lit_val_col" (just like the column reference next to it, because according to the SQL standard the names of the select expressions that don't have an explicit name specified by an AS clause are implementation dependent). So MySQL uses it to do the grouping instead of the real column value. As a result you get the displayed behaviour.
[14 Apr 2006 13:49]
Paul DuBois
I've updated the SELECT page in the manual to point out how this ambiguity can occur, and that you should use unique column names to avoid the ambiguity.