Bug #1171 Optimization for IN is broken
Submitted: 31 Aug 2003 23:20 Modified: 15 Oct 2003 5:58
Reporter: Peter Zaitsev (Basic Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.0.15-pre OS:Any (all)
Assigned to: Sergei Golubchik CPU Architecture:Any

[31 Aug 2003 23:20] Peter Zaitsev
Description:
Optimization for IN seems to be broken in 4.0.15  - this query is optimized just fine in MySQL 4.0.14 and MySQL 3.23:

MySQL 4.0.15:

mysql> explain select count(*) from rn where c in ("1");
+-------+-------+---------------+------+---------+------+------+--------------------------+
| table | type  | possible_keys | key  | key_len | ref  | rows | Extra                    |
+-------+-------+---------------+------+---------+------+------+--------------------------+
| rn    | index | NULL          | c    |      21 | NULL |   38 | Using where; Using index |
+-------+-------+---------------+------+---------+------+------+--------------------------+
1 row in set (0.00 sec)

MySQL 3.23.58:
mysql> explain select count(*) from rn where c in (1);
+-------+-------+---------------+------+---------+------+------+-------------------------+
| table | type  | possible_keys | key  | key_len | ref  | rows | Extra                   |
+-------+-------+---------------+------+---------+------+------+-------------------------+
| rn    | range | c             | c    |       5 | NULL |    1 | where used; Using index |
+-------+-------+---------------+------+---------+------+------+-------------------------+
1 row in set (0.04 sec)

This query works just fine:

explain select count(*) from rn where c=1;

How to repeat:
CREATE TABLE rn (
  c int(11) default NULL,
  KEY c (c)
) TYPE=MyISAM;

INSERT INTO rn VALUES (1),(2),(2),(2),(2),(2),(2),(2),(3),(3),(3),(3),(3),(3),(3),(3),(3),(4),(4),(4),(4),(4),(4),(4),(4),(4),(4),(5),(5),(5),(5),(5),(5),(5),(5),(5),(5),(5);

explain select count(*) from rn where c in (1);
[31 Aug 2003 23:27] Peter Zaitsev
Huh,

I just noticed I made typo in copy/paste  

using in ("1") instead of in (1) in different queries. This just does not change anything in this case - I was just trying slightly different queries to see which cases are affected.

It is broken even for most straighforward in (1)
[15 Oct 2003 5:58] Sergei Golubchik
fixed in 4.0.15