Description:
MySQL returns the wrong result with the following IN subquery :
How to repeat:
CREATE TABLE `inscrit` (
`id` mediumint(8) unsigned NOT NULL auto_increment,
`pseudo` varchar(35) character set latin1 NOT NULL default '',
PRIMARY KEY (`id`),
UNIQUE KEY `pseudo` (`pseudo`),
) TYPE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
INSERT INTO inscrit (pseudo) VALUES ('test');
SELECT 0 IN (SELECT 1 FROM taist.inscrit a);
+-------------------------------------------------------------+
| 0 IN (SELECT 1 FROM taist.inscrit a) |
+-------------------------------------------------------------+
| 0 |
+-------------------------------------------------------------+
1 row in set (0.00 sec)
=> OK
INSERT INTO inscrit (pseudo) VALUES ('test1');
SELECT 0 IN (SELECT 1 FROM taist.inscrit a);
+-------------------------------------------------------------+
| 0 IN (SELECT 1 FROM taist.inscrit a) |
+-------------------------------------------------------------+
| 1 |
+-------------------------------------------------------------+
1 row in set (0.00 sec)
=> Wrong, should still return 0
mysql> EXPLAIN SELECT 0 IN (SELECT 1 FROM taist.inscrit a);
+----+---------------------+-------+-------+---------------+---------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+---------------------+-------+-------+---------------+---------+---------+------+------+----------------+
| 1 | PRIMARY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
| 2 | DEPENDENT SUBSELECT | a | index | NULL | PRIMARY | 3 | NULL | 3 | Using index |
+----+---------------------+-------+-------+---------------+---------+---------+------+------+----------------+
MySQL seems to use the wrong index (the PRIMARY KEY here).
Description: MySQL returns the wrong result with the following IN subquery : How to repeat: CREATE TABLE `inscrit` ( `id` mediumint(8) unsigned NOT NULL auto_increment, `pseudo` varchar(35) character set latin1 NOT NULL default '', PRIMARY KEY (`id`), UNIQUE KEY `pseudo` (`pseudo`), ) TYPE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC; INSERT INTO inscrit (pseudo) VALUES ('test'); SELECT 0 IN (SELECT 1 FROM taist.inscrit a); +-------------------------------------------------------------+ | 0 IN (SELECT 1 FROM taist.inscrit a) | +-------------------------------------------------------------+ | 0 | +-------------------------------------------------------------+ 1 row in set (0.00 sec) => OK INSERT INTO inscrit (pseudo) VALUES ('test1'); SELECT 0 IN (SELECT 1 FROM taist.inscrit a); +-------------------------------------------------------------+ | 0 IN (SELECT 1 FROM taist.inscrit a) | +-------------------------------------------------------------+ | 1 | +-------------------------------------------------------------+ 1 row in set (0.00 sec) => Wrong, should still return 0 mysql> EXPLAIN SELECT 0 IN (SELECT 1 FROM taist.inscrit a); +----+---------------------+-------+-------+---------------+---------+---------+------+------+----------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+---------------------+-------+-------+---------------+---------+---------+------+------+----------------+ | 1 | PRIMARY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used | | 2 | DEPENDENT SUBSELECT | a | index | NULL | PRIMARY | 3 | NULL | 3 | Using index | +----+---------------------+-------+-------+---------------+---------+---------+------+------+----------------+ MySQL seems to use the wrong index (the PRIMARY KEY here).