Can someone tell me what is the difference between these two:
ALTER TABLE x1 ADD INDEX(a);
ALTER TABLE x1 ADD INDEX(b);
AND
ALTER TABLE x1 ADD INDEX(a,b);
I know this goes down to the very basics but sometimes I find the former seems to be a little faster than the latter. Is it just my feeling or is there some actual reason for it?
With your second option, the following query will not use the index:
The order in which columns are listed in the index definition is important. It is possible to retrieve a set of row identifiers using only the first indexed column. However, it is not possible or efficient (on most databases) to retrieve the set of row identifiers using only the second or greater indexed column.
Source: Wikipedia – Database Index: Column Ordering