tags:

views:

29

answers:

2

Somehow I managed to get two indexes named user_id, as shown below. Should I drop, rename and rebuild one of them, or is this no problem?

SHOW INDEXES FROM core_item;

+-----------+------------+-----------+--------------+-----------------+-----------+-------------+----------+--------+------+------------+---------+
| Table     | Non_unique | Key_name  | Seq_in_index | Column_name     | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-----------+------------+-----------+--------------+-----------------+-----------+-------------+----------+--------+------+------------+---------+
| core_item |          0 | PRIMARY   |            1 | id              | A         |      593642 |     NULL | NULL   |      | BTREE      |         | 
| core_item |          0 | user_id   |            1 | user_id         | A         |       11416 |     NULL | NULL   |      | BTREE      |         | 
| core_item |          0 | user_id   |            2 | product_id      | A         |      593642 |     NULL | NULL   |      | BTREE      |         |
+-----------+------------+-----------+--------------+-----------------+-----------+-------------+----------+--------+------+------------+---------+
+7  A: 

It's a single composite index covering 2 columns.

I think that output of SHOW CREATE TABLE core_item is easier to understand.

Naktibalda
+1  A: 

You have just one index, but it is across two fields - it is a composite key on user_id and product_id. It would be created like this:

ALTER TABLE core_item ADD INDEX `user_id` (`user_id`, `product_id`);

It might be worth renaming it to something else to save any future confusion, but only if the rename will not affect any existing queries that specify indexes directly.

Mike