I wanted to share a little rule of thumb I sometimes use to decide which columns should come first in an index. This is not specific to MySQL, it's generally applicable to any database server with b-tree indexes. And there are a bunch of subtleties, but I will also ignore those for the sake of simplicity.
Let's start with this query, which returns zero rows but does a full table scan. EXPLAIN says there are no possible_keys.
PLAIN TEXT SQL:
- SELECT * FROM tbl WHERE STATUS='waiting' AND source='twitter'
- AND no_send_before <= '2009-05-28 03:17:50' AND tries <= 20
- ORDER BY date ASC LIMIT 1;
Don't try to figure out the meaning of the query, because that'll add complexity to the example In the simplest case, we want to put the most …
[Read more]