What is database indexing and primary keys?

Avatar
  • Answered
I'm trying to check my tables to see why my DB is acting slow and I get this message:

The indexes PRIMARY and id seem to be equal and one of them could possibly be removed.

I don't have a column called Primary, though I have one called ID.
Avatar
Tim S.
Hi stu,

Thanks for posting your question. I'm more than happy to assist you today. PRIMARY is a reference to the primary key for the table. A PRIMARY KEY is a field or column on the table, when each row is inserted it must be unique. Since it must be unique, it should not exist in the table anywhere else.

To speed up the process, MySQL creates indexes for such fields, so they can quickly detect if a value already exists in the field, without having to check every row in the table itself.

So manually creating indexes on fields already set to PRIMARY KEY or UNIQUE is redundant and can cause performance issues due to the duplication in the indexes.

Did you create one of these unique fields in the table yourself? That is likely the cause since there's already a primary key set and it is being indexed. Typically, you can remove the duplicate field.

I hope this explanation of primary keys and indexes helps you. If you need further assistance please feel free to contact us.

Thanks!

Tim S