Bug #48731 Subquery in select with wrong column name is ignored
Submitted: 12 Nov 2009 14:46 Modified: 12 Nov 2009 15:08
Reporter: Zigmund Bulinsh Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.1.40 OS:Windows
Assigned to: CPU Architecture:Any

[12 Nov 2009 14:46] Zigmund Bulinsh
Description:
Subquery in select with wrong column name is ignored

How to repeat:
Load attached dump.

Server version: 5.1.40-community-log MySQL Community Server (GPL)
mysql> select
    ->   A.id,
    ->   (select projects from v_sigma1 where id = A.id) projects,
    ->   (select projects from v_sigma2 where id = A.id) tasks,
    ->   (select projects from v_sigma3 where id = A.id) sub_tasks
    -> from users as A;
+----+----------+-------+-----------+
| id | projects | tasks | sub_tasks |
+----+----------+-------+-----------+
| 16 |        6 |     6 |         6 |
| 18 |        1 |     1 |         1 |
+----+----------+-------+-----------+
2 rows in set (0.00 sec)

mysql> select projects from v_sigma2 where id = 16;
ERROR 1054 (42S22): Unknown column 'projects' in 'field list'
mysql> select projects from v_sigma3 where id = 16;
ERROR 1054 (42S22): Unknown column 'projects' in 'field list'

And then ask yourself a question: How MySQL selected column "projects" from v_sigma2, v_sigma3 tables where such column does not exist???
[12 Nov 2009 14:47] Zigmund Bulinsh
Dump

Attachment: test.sql (application/octet-stream, text), 3.92 KiB.

[12 Nov 2009 15:08] Zigmund Bulinsh
Not a bug.