Bug #3638 EXPLAIN says nothing about external Sort and temporary tables done at UNION
Submitted: 3 May 2004 22:09 Modified: 4 May 2004 22:09
Reporter: Peter Zaitsev (Basic Quality Contributor) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.2 OS:Any (all)
Assigned to: CPU Architecture:Any

[3 May 2004 22:09] Peter Zaitsev
Description:
As you can see from EXPLAIN below we do not have any information about filesort
being done as well as about temporary table created for its resolution. 

mysql> explain (select * from a) union (select * from b) order by c;
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| 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)

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

--
-- Dumping data for table `a`
--

INSERT INTO a VALUES (1,'a'),(1,'a'),(2,'a'),(3,'a'),(101,'a'),(101,'a'),(102,'a'),(103,'a'),(101,'a'),(101,'a'),(102,'a'),(103,'a'),(201,'a'),(201,'a'),(202,'a'),(203,'a'),(101,'a'),(101,'a'),(102,'a'),(103,'a'),(201,'a'),(201,'a'),(202,'a'),(203,'a'),(201,'a'),(201,'a'),(202,'a'),(203,'a'),(301,'a'),(301,'a'),(302,'a'),(303,'a'),(101,'a'),(101,'a'),(102,'a'),(103,'a'),(201,'a'),(201,'a'),(202,'a'),(203,'a'),(201,'a'),(201,'a'),(202,'a'),(203,'a'),(301,'a'),(301,'a'),(302,'a'),(303,'a'),(201,'a'),(201,'a'),(202,'a'),(203,'a'),(301,'a'),(301,'a'),(302,'a'),(303,'a'),(301,'a'),(301,'a'),(302,'a'),(303,'a'),(401,'a'),(401,'a'),(402,'a'),(403,'a'),(101,'a'),(101,'a'),(102,'a'),(103,'a'),(201,'a'),(201,'a'),(202,'a'),(203,'a'),(201,'a'),(201,'a'),(202,'a'),(203,'a'),(301,'a'),(301,'a'),(302,'a'),(303,'a'),(201,'a'),(201,'a'),(202,'a'),(203,'a'),(301,'a'),(301,'a'),(302,'a'),(303,'a'),(301,'a'),(301,'a'),(302,'a'),(303,'a'),(401,'a'),(401,'a'),(402,'a'),(403,'a'),(201,'a'),(201,'a'),(202,'a'),(203,'a'),(301,'a'),(301,'a'),(302,'a'),(303,'a'),(301,'a'),(301,'a'),(302,'a'),(303,'a'),(401,'a'),(401,'a'),(402,'a'),(403,'a'),(301,'a'),(301,'a'),(302,'a'),(303,'a'),(401,'a'),(401,'a'),(402,'a'),(403,'a'),(401,'a'),(401,'a'),(402,'a'),(403,'a'),(501,'a'),(501,'a'),(502,'a'),(503,'a');

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

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

--
-- Dumping data for table `b`
--

INSERT INTO b VALUES (1,'b'),(2,'b'),(3,'b'),(4,'b'),(101,'b'),(102,'b'),(103,'b'),(104,'b'),(101,'b'),(102,'b'),(103,'b'),(104,'b'),(201,'b'),(202,'b'),(203,'b'),(204,'b'),(101,'b'),(102,'b'),(103,'b'),(104,'b'),(201,'b'),(202,'b'),(203,'b'),(204,'b'),(201,'b'),(202,'b'),(203,'b'),(204,'b'),(301,'b'),(302,'b'),(303,'b'),(304,'b'),(101,'b'),(102,'b'),(103,'b'),(104,'b'),(201,'b'),(202,'b'),(203,'b'),(204,'b'),(201,'b'),(202,'b'),(203,'b'),(204,'b'),(301,'b'),(302,'b'),(303,'b'),(304,'b'),(201,'b'),(202,'b'),(203,'b'),(204,'b'),(301,'b'),(302,'b'),(303,'b'),(304,'b'),(301,'b'),(302,'b'),(303,'b'),(304,'b'),(401,'b'),(402,'b'),(403,'b'),(404,'b'),(101,'b'),(102,'b'),(103,'b'),(104,'b'),(201,'b'),(202,'b'),(203,'b'),(204,'b'),(201,'b'),(202,'b'),(203,'b'),(204,'b'),(301,'b'),(302,'b'),(303,'b'),(304,'b'),(201,'b'),(202,'b'),(203,'b'),(204,'b'),(301,'b'),(302,'b'),(303,'b'),(304,'b'),(301,'b'),(302,'b'),(303,'b'),(304,'b'),(401,'b'),(402,'b'),(403,'b'),(404,'b'),(201,'b'),(202,'b'),(203,'b'),(204,'b'),(301,'b'),(302,'b'),(303,'b'),(304,'b'),(301,'b'),(302,'b'),(303,'b'),(304,'b'),(401,'b'),(402,'b'),(403,'b'),(404,'b'),(301,'b'),(302,'b'),(303,'b'),(304,'b'),(401,'b'),(402,'b'),(403,'b'),(404,'b'),(401,'b'),(402,'b'),(403,'b'),(404,'b'),(501,'b'),(502,'b'),(503,'b'),(504,'b');

explain (select * from a) union (select * from b) order by c;
[4 May 2004 22:09] Michael Widenius
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem is not the result of a bug.
For a list of more appropriate places to ask for help using MySQL
products, please visit http://www.mysql.com/support/

Thank you for your interest in MySQL.

Additional info:

This can't be done with current EXPLAIN but left to future explain versions.

(This is also not a bug and should not be in the bugs databases)