I mean what are the possible cases where a MySQL query does not occupy the indexes created on a table. I ask because I perform a query where I get 39000 records out of 41000 existing ones, using the statement explain
I can notice that the indexes of the table are not being used. So can it be because it only fetches records from a single table and it's almost all of them? and if so, in what other cases could the same thing happen (indices not being used)?
MySQL uses the indexes it deems convenient to optimize the results based on the columns found in the section
WHERE
, regardless of the order in which they are found. Let's see the example using the following DDL:And with the following set of test data:
When executing the
EXPLAIN
on the queries we obtain interesting results:It should be noted that you can force the use of a particular index by means of the statement
FORCE INDEX
, as will be seen in the following cases: