Two duplicate indexes with the same columns

前端 未结 2 1496
独厮守ぢ
独厮守ぢ 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.

提交回复
热议问题