Bug #3639 EXPLAIN accepts query which references non existing object
Submitted: 3 May 2004 22:14 Modified: 19 May 2004 17:41
Reporter: Peter Zaitsev (Basic Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.2 OS:Any (all)
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[3 May 2004 22:14] Peter Zaitsev
Description:
mysql> explain (select * from a) union (select * from b) order by silly_column;
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
|  1 | PRIMARY     | a     | ALL  | NULL          | NULL |    NULL | NULL |  129 |       |
|  2 | UNION       | b     | ALL  | NULL          | NULL |    NULL | NULL |  129 |       |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
2 rows in set (0.00 sec)

The columns in order_by does not exist so this query should terminate with unknown column query, while explain is printed.

This is perhaps reated to the fact no information is printed about external order by done at all. 

How to repeat:
CREATE TABLE a (
  i int(11) default NULL,
  c char(1) default NULL,
  KEY i (i)
) ;

--
-- Table structure for table `b`
--

CREATE TABLE b (
  i int(11) default NULL,
  c char(1) default NULL,
  KEY i (i)
) ;

explain (select * from a) union (select * from b) order by silly_column;
[6 May 2004 20:05] Oleksandr Byelkin
ChangeSet 
  1.1817 04/05/06 20:40:21 bell@sanja.is.com.ua +11 -0 
  EXPLAIN UNION using same routing which used for execution which allow return 
correct bug messages (Bug #3639) 
  EXPLAIN of hidden SELECT of UNION
[19 May 2004 17:41] Oleksandr Byelkin
Thank you for bug report. fix for this bug pushed in our internal repository