Monday, February 2, 2015

MySQL performance

Indexing of MySQL tables is crucial, too little is bad and too much is bad as well. Best practice is to work tightly with DESCRIBE command and index columns used in JOIN and WHERE clauses.

There are several situations, where indexes can’t be used. If you perform LIKE wildcard search, only col LIKE ’abc%’ or col LIKE ’a%c%’ use indexes, but col LIKE ’%abc%’ and col LIKE %abc’ and col LIKE col2 don’t – because of the way B-Tree index is designed. Or if you have to do a string operation before comparison, e.g. UPPER(col) LIKE ’ABC’, all rows has to be loaded. In such case consider adding a new column, with cached upper-case values.