How are multiple indexes used in a query by MySQL?
MySQL is capable of doing an INDEX MERGE which allows MySQL to search on both indexes and merge the results. Of course, the MySQL Query Optimizer is the arbitrator of this process.

From my perspective, just looking at your query and its WHERE clause, I would create a compound index on your table and an additional index. Which compound index, (a,b) or (b,a) ?

I would next check the cardinality of each column as follows:

SELECT COUNT(DISTINCT a) a_count FROM `table`;
SELECT COUNT(DISTINCT b) b_count FROM `table`;


Based on these counts


If a_count &lt; b_count, then I would create compound index (a,b) and an index on b
If a_count > b_count, then I would create compound index (b,a) and an index on a
If a_count = b_count, then I would create one pair or other


For more information, please read the following links:


http://www.mysqlperformanceblog.com/2009/09/19/multi-column-indexes-vs-index-merge/
http://brian.moonspot.net/2008/04/22/playing-with-mysql-index-merge/
http://use-the-index-luke.com/sql/where-clause/searching-for-ranges/index-merge-performance