Forum Moderators: phranque
Create table table1(
a varchar(100),
b varchar(100),
c char(1),
d varchar(255);
The query is
select a, b, c from table1 where b like '%happiness%' and a in ('algeria', 'china') and c = 'N';
There is an index on a and an index on c and an index on a and c but it is still slow.
After creating the index, table1 is analyzed and optimized.
From my understanding MySQL will only ever use 1 index during a query, thats why its usefull sometimes to use 1 index to index mulitiple columns.
From the manual :-
If the table has a multiple-column index, any leftmost prefix of the index can be used by the optimizer to find 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).
Plus MySQL will not use an index if a LIKE '%SEARCHSTRING%' is used.