Bug #38958 | 'SELECT DISTINCT ... EXISTS' returns wrong result set, if used with indexs | ||
---|---|---|---|
Submitted: | 22 Aug 2008 10:56 | Modified: | 27 Aug 2008 15:31 |
Reporter: | Gregor Weckbecker | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server | Severity: | S2 (Serious) |
Version: | MySQL 5.0.51a-3ubuntu5.1 | OS: | Linux (ubuntu) |
Assigned to: | CPU Architecture: | Any |
[22 Aug 2008 10:56]
Gregor Weckbecker
[22 Aug 2008 13:27]
MySQL Verification Team
Thank you for the bug report. Could you please try with the latest released version 5.0.67. Thanks in advance.
[22 Aug 2008 14:32]
Gregor Weckbecker
I've tried the newest mysql - release: It simply rejects the query with the message: mysql> SELECT distinct taggable_id AS tagbl_id, taggable_type AS tagbl_type -> FROM `taggings` -> WHERE ( -> (EXISTS -> (SELECT taggable_id,taggable_type -> FROM taggings -> WHERE tag_id = 2 AND taggable_id = tagbl_id AND taggable_type = tagbl_type) -> ) -> ); ERROR 1054 (42S22): Unknown column 'tagbl_id' in 'where clause'
[27 Aug 2008 15:31]
MySQL Verification Team
Thank you for your bug report. This issue has already been fixed in the latest released version of that product, which you can download at http://www.mysql.com/downloads/ Additional Info: The initial bug report was a bug, but MySQL behaviour is correct with the latest version. Statements of the form SELECT select_list FROM from_tables WHERE where_conditions; are resolved in this order: from_tables, where_conditions, select_list. So at the time that a DBMS evaluates where_conditions it knows nothing about names that will be established with select_list. For example: CREATE TABLE t (s1 INT); SELECT s1 AS s2 FROM t WHERE s2 = 5; gives the same error.