Having duplicate keys in our schemas can hurt the performance of our database:
- They make the optimizer phase slower because MySQL needs to examine more query plans.
- The storage engine needs to maintain, calculate and update more index statistics
- DML and even read queries can be slower because MySQL needs update fetch more data to Buffer Pool for the same load
- Our data needs more disk space so our backups will be bigger and slower
In this post I’m going to explain the different types of duplicate indexes and how to find and remove them.
Duplicate keys on the same column
This is the easiest one. You can create multiple indexes on the same column and MySQL won’t complain. Let’s see this example:
mysql> alter table t add index(name);
mysql> alter table t add index(name);
…