Bug #18520 Index V not used for 'where V' and 'where not V'
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>
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.051 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.