Description:
The optimizer is unable to use indexes for V or not V.
V should be equivalent to V != 0 and
V should be equivalent to V = 0.
How to repeat:
CREATE TABLE `xcl_input` (
`iid` int(11) NOT NULL auto_increment,
`d` blob NOT NULL,
`ipa` int(11) NOT NULL,
`gid` int(11) NOT NULL default '0',
`ws_gid` int(11) NOT NULL,
`mtime` int(11) NOT NULL,
PRIMARY KEY (`iid`),
KEY `ws_gid` (`ws_gid`)
);
mysql> explain select iid, d from xcl_input where ws_gid order by iid limit 100;
+----+-------------+-----------+-------+---------------+---------+---------+------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+-------+---------------+---------+---------+------+--------+-------------+
| 1 | SIMPLE | xcl_input | index | NULL | PRIMARY | 4 | NULL | 285511 | Using where |
+----+-------------+-----------+-------+---------------+---------+---------+------+--------+-------------+
1 row in set (0.00 sec)
mysql> explain select iid, d from xcl_input where ws_gid != 0 order by iid limit 100;
+----+-------------+-----------+-------+---------------+--------+---------+------+--------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+-------+---------------+--------+---------+------+--------+-----------------------------+
| 1 | SIMPLE | xcl_input | range | ws_gid | ws_gid | 4 | NULL | 285367 | Using where; Using filesort |
+----+-------------+-----------+-------+---------------+--------+---------+------+--------+-----------------------------+
1 row in set (0.00 sec)
mysql> explain select iid, d from xcl_input where ws_gid = 0 order by iid limit 100;
+----+-------------+-----------+------+---------------+--------+---------+-------+------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+------+---------------+--------+---------+-------+------+-----------------------------+
| 1 | SIMPLE | xcl_input | ref | ws_gid | ws_gid | 4 | const | 145 | Using where; Using filesort |
+----+-------------+-----------+------+---------------+--------+---------+-------+------+-----------------------------+
1 row in set (0.00 sec)
mysql> explain select iid, d from xcl_input where not ws_gid order by iid limit 100;
+----+-------------+-----------+-------+---------------+---------+---------+------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+-------+---------------+---------+---------+------+--------+-------------+
| 1 | SIMPLE | xcl_input | index | NULL | PRIMARY | 4 | NULL | 285511 | Using where |
+----+-------------+-----------+-------+---------------+---------+---------+------+--------+-------------+
1 row in set (0.00 sec)
mysql>