I've been dropped in a system that was poorly designed. Now I'm doing DBA on their DB, and I have a lot of situation like the following (Pseudo-code):
Table t1{
c1;
c2;
c3;
c4;
key(c1);
key(c2);
key(c1,c2);
key(c1,c2,c3);}
Are the single column indexes really necessary, since I already have a multicolumn one containing those columns?
Or on the other hand - is the multiline column needed since I already have the single column ones?
A short excerpt from the documentation page about how MySQL uses indexes:
If the table has a multiple-column index, any leftmost prefix of the index can be used by the optimizer to look up rows. For example, if you have a three-column index on (
col1
,col2
,col3
), you have indexed search capabilities on (col1
), (col1
,col2
), and (col1
,col2
,col3
). For more information, see Section 8.3.5, “Multiple-Column Indexes”.
You better remove the indexes on (c1)
and (c1,c2)
. They are not used but they use storage space and consume processor power to be kept up-to-date when the table data changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With