Two duplicate indexes with the same columns

前端 未结 2 1484
独厮守ぢ
独厮守ぢ 2021-01-04 03:17

I am looking at a table in our database (I didn\'t make the table), and I see that there are 2 indexes that are exactly the same (I don\'t know why this was done) just named

相关标签:
2条回答
  • 2021-01-04 03:42

    Yes, it can have an effect.

    Of course the two indexes take extra space on disk and also in memory if they are used.

    But they also cause the query optimizer to do more work to calculate the benefit of each index during every SELECT. The more indexes you have, the more cases it has to compare. So it pays off to eliminate truly redundant indexes.

    As others have also noted, indexes are updated during INSERT/UPDATE/DELETE operations, so the more indexes you have, the more overhead this represents. Indexes that get a lot of use justify their own overhead, but duplicate indexes take more overhead with no additional benefit to match.

    If you're interested, Percona Toolkit has a tool pt-duplicate-key-checker that searches all your tables for cases like this.

    0 讨论(0)
  • 2021-01-04 04:00

    Yes, it will impact performance. Every time you write a new row or change the user_id, MySQL has to write three times: once to the table, once to the user_id_idx index, and once to the user_id_2 index. I'd get rid of one of them.

    Before dropping the extra index, make sure it's not referenced anywhere. For the most part indexes aren't mentioned by name, but there are exceptions such as index hints.

    0 讨论(0)
提交回复
热议问题