I have a table that I created many years ago. All of my queries are like:
SELECT colA FROM table
WHERE colB = '' OR colB = 'foo'
I had originally created an index on colA and colB (named ORIGINAL, with Cardinality of 83). But now I'm pretty sure that the index only needs to be on colB (the WHERE conditions).
So I created a second index that's just on colB (named NEW, with a Cardinality of 1), then ran:
EXPLAIN
SELECT colA FROM table
WHERE colB = '' OR colB = 'foo'
It returns:
type: index
possible_keys: NEW
key: ORIGINAL
Extra: Using where; Using index
So it's using the index with the WHERE columns AND the SELECT columns!
Then I deleted the ORIGINAL index, and now EXPLAIN shows that it doesn't use an index at all!
Does that mean that I
should include the columns in the SELECT, too?
In this table of 83 rows, the speed difference is insignificant. But this is just a test run, and the result is going to affect whether I rebuild much larger tables.