Bug #6187 Explain for a query with constant false XOR condition returns a wrong comment.
Submitted: 20 Oct 2004 21:15 Modified: 23 Oct 2004 2:10
Reporter: Igor Babaev Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.2 OS:Any (all)
Assigned to: Igor Babaev CPU Architecture:Any

[20 Oct 2004 21:15] Igor Babaev
Description:
The following EXPLAIN command:   
 EXPLAIN SELECT * FROM t1 WHERE (1 XOR 1);   
returns  
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+  
| id | select_type | table | type | possible_keys | key  | key_len | ref  |  
rows | Extra                                               |  
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+  
|  1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL |  
NULL | Impossible WHERE noticed after reading const tables |  
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+  
  
It should return:  
+----+-------------+-------+------+---------------+------+---------+------+------+------------------+ 
| id | select_type | table | type | possible_keys | key  | key_len | ref  | 
rows | Extra            | 
+----+-------------+-------+------+---------------+------+---------+------+------+------------------+ 
|  1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | 
NULL | Impossible WHERE | 
+----+-------------+-------+------+---------------+------+---------+------+------+------------------+ 
   

How to repeat:
mysql> create table t1 (a int); 
Query OK, 0 rows affected (0.00 sec) 
 
mysql> insert into t1 values (1), (2); 
Query OK, 2 rows affected (0.00 sec) 
Records: 2  Duplicates: 0  Warnings: 0 
 
mysql> EXPLAIN SELECT * FROM t1 WHERE (1 XOR 1); 
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+ 
| id | select_type | table | type | possible_keys | key  | key_len | ref  | 
rows | Extra                                               | 
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+ 
|  1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | 
NULL | Impossible WHERE noticed after reading const tables | 
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+ 
1 row in set (0.00 sec) 
 

Suggested fix:
The problem is a result of an incorrect initial setting for const_item_cache 
in Item_cond::fix_fields. 
The same bug exists in Item_cond::split_sum_func.
[20 Oct 2004 21:18] Igor Babaev
The bug can be found in all versions down to 3.23.  
Probably it makes sense to downport the fix.
[23 Oct 2004 2:10] Igor Babaev
ChangeSet
  1.1663 04/10/20 14:52:30 igor@rurik.mysql.com +2 -0
  func_test.result, item_cmpfunc.cc:
    Fixed bug #6187: a wrong initial setting for const_item_cache
    in Item_cond::fix_fields.

As I mentioned the fix probably should be downported.