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
  •  | 
  •  

Pregunta

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!

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top