Short answer Remove the shorter index.
Long Anwser Things to consider:
Drop it:
- Each
INDEX is a separate bit that is on the disk, so it occupies a space. - Each
INDEX updated (sooner or later) when an INSERT new row or UPDATE changes an indexed column. This takes up some CPU and I / O space and buffer_pool for the change buffer. - Any functional use (as opposed to performance) for a shorter index can be made longer.
Do not drop it:
- A longer index is more cumbersome than a shorter one. Thus, it is less cached. Thus (in extreme situations) the use of more cumbersome, instead of shorter, can lead to more I / O. A case that exacerbates this is:
INDEX(int, varchar255) .
It is very rare that the last element really overrides the other elements.
Bonus
A "covering" index is one that contains all the columns specified in the SELECT . For instance:
SELECT status FROM tbl WHERE owner = 123;
This only affects BTree for INDEX(owner, status) , which is noticeably faster than
SELECT status, foo FROM tbl WHERE owner = 123;
If you really need this query faster, replace both indexes with INDEX(owner, status, foo) .
PC in an additional key
Another tidbit ... In InnoDB, PRIMARY KEY columns are implicitly added to each secondary key. So, three examples are really
INDEX(owner, id) INDEX(owner, status, id) INDEX(owner, status, foo, id)
More discussions on my blogs on composite indexes and index cookbook .
source share