Is it necessary to have a PRIMARY index AND colname index on the primary key column?

StackOverflow https://stackoverflow.com/questions/7494120

  •  24-01-2021
  •  | 
  •  

質問

Imagine the following table:

Simple single row table.

Colname = id int(11)

+---------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table               | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| tablename           |          0 | PRIMARY  |            1 | id          | A         |     1719077 |     NULL | NULL   |      | BTREE      |         |               |
| tablename           |          0 | id       |            1 | id          | A         |     1719077 |     NULL | NULL   |      | BTREE      |         |               |
+---------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+

That is the dump of show indexes in tablename.

I think this is a 'bug' in the mysql manager I use (ems mysql manager) where when you create a table with a primary key, it will create both a PRIMARY index (the name of the actual index is PRIMARY) and also a primary-key-colname index automatically on table creation.

Is it ok to remove one of these?

Thanks!

役に立ちましたか?

解決

Absolutely. The primary key will function just fine as an index.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top