Bug #60026 | Optimize for NULL parameter to IN() | ||
---|---|---|---|
Submitted: | 9 Feb 2011 0:29 | Modified: | 9 Feb 2011 7:22 |
Reporter: | Todd Farmer (OCA) | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S4 (Feature request) |
Version: | OS: | Any | |
Assigned to: | CPU Architecture: | Any |
[9 Feb 2011 0:29]
Todd Farmer
[9 Feb 2011 7:22]
Valeriy Kravchuk
Verified just as described: C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -uroot -proot -P3312 test Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 5.5.8 MySQL Community Server (GPL) Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> drop table t1; Query OK, 0 rows affected (0.03 sec) mysql> CREATE TABLE `t1` ( -> `a` int(11) NOT NULL, -> `b` int(11) NOT NULL, -> `c` int(11) default NULL, -> KEY `a` (`a`), -> KEY `b` (`b`) -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 -> ; Query OK, 0 rows affected (0.19 sec) mysql> insert into t1 values (1,1,1); Query OK, 1 row affected (0.05 sec) mysql> explain select * from t1 where b in (NULL); +----+-------------+-------+------+---------------+------+---------+------+----- -+-----------------------------------------------------+ | 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.01 sec) mysql> explain select * from t1 where c in (NULL); +----+-------------+-------+------+---------------+------+---------+------+----- -+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+----- -+-------------+ | 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 1 | Using where | +----+-------------+-------+------+---------------+------+---------+------+----- -+-------------+ 1 row in set (0.03 sec) Note that for some engines optimizer is able to process this case correctly even when column has no index: mysql> alter table t1 engine=MyISAM; Query OK, 1 row affected (0.23 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> explain select * from t1 where c in (NULL); +----+-------------+-------+------+---------------+------+---------+------+----- -+-----------------------------------------------------+ | 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)