Bug #6252 MyISAM tables: Same column several times in index
Submitted: 25 Oct 2004 19:40 Modified: 22 Nov 2004 18:09
Reporter: Carsten Pedersen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S2 (Serious)
Version:4.1.6 OS:Linux (Linux / SuSE 9.1)
Assigned to: Antony Curtis CPU Architecture:Any

[25 Oct 2004 19:40] Carsten Pedersen
Description:
When creating a MyISAM table, you can specify the same column several times in a single index.

The standard says (in the syntax rules for a primary/unique key):
3) If <unique column list> UCL is specified, then
  a) Each <column name> in the <unique column list> shall
     identify a column of T, and the same column shall not be
     identified more than once.

So, duplicating a column in the column list of either a
PRIMARY KEY or a UNIQUE key is not allowed.

How to repeat:
mysql> create table t (i1 int not null, primary key (i1, i1, i1)) engine=myisam;
Query OK, 0 rows affected (0.00 sec)

mysql> desc t;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| i1    | int(11) |      | PRI | 0       |       |
+-------+---------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql> show indexes from t;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| t     |          0 | PRIMARY  |            1 | i1          | A         |        NULL |     NULL | NULL   |      | BTREE      |         |
| t     |          0 | PRIMARY  |            2 | i1          | A         |        NULL |     NULL | NULL   |      | BTREE      |         |
| t     |          0 | PRIMARY  |            3 | i1          | A         |           0 |     NULL | NULL   |      | BTREE      |         |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
3 rows in set (0.00 sec)

Suggested fix:
Disallow the same column from appearing more than once in an index during CREATE and ALTER
[19 Nov 2004 16:22] Antony Curtis
1st review completed by Sanja
[22 Nov 2004 18:00] Antony Curtis
2nd review by Konstantin
[22 Nov 2004 18:09] Antony Curtis
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