Bug #30372 STRAIGHT JOIN somehow loses table/column references in SELECT list
Submitted: 11 Aug 2007 16:02 Modified: 11 Aug 2007 23:14
Reporter: Tobias Asplund Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Parser Severity:S3 (Non-critical)
Version:5.0.45/4.1/5.1 OS:Linux
Assigned to: Igor Babaev CPU Architecture:Any

[11 Aug 2007 16:02] Tobias Asplund
Description:
mysql> CREATE TABLE bug1 ( a INT, b INT );
Query OK, 0 rows affected (0.11 sec)

mysql> CREATE TABLE bug2 ( c INT );
Query OK, 0 rows affected (0.04 sec)

mysql> INSERT INTO bug1 VALUES (1, 1);
Query OK, 1 row affected (0.05 sec)

mysql> INSERT INTO bug2 VALUES (1);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT bug1.b FROM bug1 STRAIGHT JOIN bug2 ON a = c;
ERROR 1054 (42S22): Unknown column 'bug1.b' in 'field list'

However, this works:
mysql> SELECT * FROM bug1 STRAIGHT JOIN bug2 ON a = c;
+------+------+------+
| a    | b    | c    |
+------+------+------+
|    1 |    1 |    1 | 
+------+------+------+
1 row in set (0.00 sec)

And this:
mysql> SELECT STRAIGHT_JOIN bug1.b FROM bug1 JOIN bug2 ON a = c;
+------+
| b    |
+------+
|    1 | 
+------+
1 row in set (0.00 sec)

It just feels like something is wrong here.

How to repeat:
CREATE TABLE bug1 ( a INT, b INT );
CREATE TABLE bug2 ( c INT );
INSERT INTO bug1 VALUES (1, 1);
INSERT INTO bug2 VALUES (1);
SELECT bug1.b FROM bug1 STRAIGHT JOIN bug2 ON a = c;
DROP TABLE bug1;
DROP TABLE bug2;
[11 Aug 2007 18:04] MySQL Verification Team
Thank you for the bug report. Verified as described.
[11 Aug 2007 23:14] Igor Babaev
MySQL allows you to use only the 'STRAIGHT_JOIN' hint for a join operation (but no 'STRAIGHT JOIN').

Thus in the query
SELECT bug1.b FROM bug1 STRAIGHT JOIN bug2 ON a = c;
'STRAIGHT' is considered as an alias for table 'bug1' hiding the name 
of the table. 

So the above query is equiavalent to the query
SELECT bug1.b FROM bug1 s JOIN bug2 ON a = c;
for which the returned error message looks quite natural:

mysql> SELECT bug1.b FROM bug1 S JOIN bug2 ON a = c;
ERROR 1054 (42S22): Unknown column 'bug1.b' in 'field list'

Use 'STRAIGHT_JOIN' and you'll get the expected output:

ysql> SELECT bug1.b FROM bug1 STRAIGHT_JOIN bug2 ON a = c;
------+
 b    |
------+
    1 |
------+