Bug #2295 Indexing causes a query to fail
Submitted: 6 Jan 2004 5:58 Modified: 15 Jan 2004 7:25
Reporter: Tim McCutcheon Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.0.17-standard OS:Linux (Linux/Redhat 9.0)
Assigned to: Sergei Golubchik CPU Architecture:Any

[6 Jan 2004 5:58] Tim McCutcheon
Description:
Creation of an index on three text fields causes a query to fail.

The exact same query without an index suceeds.

How to repeat:
CREATE INDEX AND DO SELECT:
mysql> CREATE INDEX idxChild ON Child (other_code(10), CommonField(10), ChildField(10));
Query OK, 1089 rows affected (0.26 sec)
Records: 1089  Duplicates: 0  Warnings: 0

mysql> SELECT PlanLine1 FROM Child WHERE other_code='807780' AND CommonField='477' AND ChildField='165';
Empty set (0.00 sec)

mysql> EXPLAIN SELECT PlanLine1 FROM Child WHERE other_code='807780' AND CommonField='477' AND ChildField='165';
+-------+-------+---------------+------+---------+------+------+-------+
| table | type  | possible_keys | key  | key_len | ref  | rows | Extra |
+-------+-------+---------------+------+---------+------+------+-------+
| Child | const | idxChild      | NULL |    NULL | NULL |    1 |       |
+-------+-------+---------------+------+---------+------+------+-------+
1 row in set (0.00 sec)

SAME QUERY - JUST DROP QUOTE ON ONE FIELD:

mysql> SELECT PlanLine1 FROM Child WHERE other_code='807780' AND CommonField=477 AND ChildField='165';
+-----------+
| PlanLine1 |
+-----------+
| Tim Test  |
+-----------+
1 row in set (0.00 sec)

mysql> EXPLAIN SELECT PlanLine1 FROM Child WHERE other_code='807780' AND CommonField=477 AND ChildField='165';
+-------+------+---------------+----------+---------+-------+------+-------------+
| table | type | possible_keys | key      | key_len | ref   | rows | Extra       |
+-------+------+---------------+----------+---------+-------+------+-------------+
| Child | ref  | idxChild      | idxChild |      12 | const |   37 | Using where |
+-------+------+---------------+----------+---------+-------+------+-------------+
1 row in set (0.00 sec)

DROP INDEX:
mysql> drop index idxChild on Child;
Query OK, 1089 rows affected (0.19 sec)
Records: 1089  Duplicates: 0  Warnings: 0

mysql> SELECT PlanLine1 FROM Child WHERE other_code='807780' AND CommonField='477' AND ChildField='165';
+-----------+
| PlanLine1 |
+-----------+
| Tim Test  |
+-----------+
1 row in set (0.06 sec)

mysql> EXPLAIN SELECT PlanLine1 FROM Child WHERE other_code='807780' AND CommonField='477' AND ChildField='165';
+-------+------+---------------+------+---------+------+------+-------------+
| table | type | possible_keys | key  | key_len | ref  | rows | Extra       |
+-------+------+---------------+------+---------+------+------+-------------+
| Child | ALL  | NULL          | NULL |    NULL | NULL | 1089 | Using where |
+-------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

ALL THREE FIELDS ARE TEXT:
| ChildField                   | text |      |     |         |       |
| CommonField                  | text |      |     |         |       |
| other_code                   | text |      | MUL |         |       |
[6 Jan 2004 6:30] MySQL Verification Team
To repeat a bug we need your table.

Can you tar it and gzip it and upload it tho this bug record ??
[14 Jan 2004 4:34] MySQL Verification Team
I verified it against 4.0.18 with a file provided by user.
[15 Jan 2004 7:25] Sergei Golubchik
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:

fixed in 4.0.18