Bug #3666 'Only index' for tables of type 'const' fix doesn't work properly
Submitted: 5 May 2004 20:02 Modified: 6 May 2004 3:42
Reporter: jocelyn fournier (Silver Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.1.2 bk tree OS:Linux (Linux)
Assigned to: Michael Widenius CPU Architecture:Any

[5 May 2004 20:02] jocelyn fournier
Description:
Hi,

Since the change "'only index' for tables of type 'const'" introduced with ChangeSet 1.1799, MySQL results erroneous results on some of my queries using tables of type 'const'.

Regards,
  Jocelyn

How to repeat:
CREATE TABLE `bug` (
  `numeropost` mediumint(8) unsigned NOT NULL default '0',
  `numreponse` int(10) unsigned NOT NULL auto_increment,
  PRIMARY KEY  (`numeropost`,`numreponse`),
  UNIQUE KEY `numreponse` (`numreponse`),
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO bug (numeropost,numreponse) VALUES ('1','1'),('1','2'),('2','3'),('2','4');

SELECT numeropost FROM bug WHERE numreponse='1';

+------------+
| numeropost |
+------------+
|          2 |
+------------+
1 row in set (0.00 sec)

=> it should returns 1

mysql> EXPLAIN SELECT numeropost FROM bug WHERE numreponse='1';
+----+-------------+-------+-------+---------------+------------+---------+-------+------+-------------+
| id | select_type | table | type  | possible_keys | key        | key_len | ref   | rows | Extra       |
+----+-------------+-------+-------+---------------+------------+---------+-------+------+-------------+
|  1 | SIMPLE      | bug   | const | numreponse    | numreponse |       4 | const |    1 | Using index |
+----+-------------+-------+-------+---------------+------------+---------+-------+------+-------------+
1 row in set (0.00 sec)

mysql> FLUSH TABLES;
Query OK, 0 rows affected (9.43 sec)

mysql> SELECT numeropost FROM bug WHERE numreponse='1';
+------------+
| numeropost |
+------------+
|          0 |
+------------+
1 row in set (0.00 sec)
[6 May 2004 3:42] Michael Widenius
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

I made a small typo in my previous patch that caused this problem.
This is now fixed. Thanks for noticing this!

Regards,
Monty