I created a table which has close to 800,000 records.
mysql> describe automation_search_test;
+----------+---------+------+-----+---------+---------------
Since SELECT
without a WHERE
condition returns all of the values in that column, there is nothing for the index to do.
That's a bit like asking why the index at the back of a textbook isn't used when I want to read the whole book.
It sounds as if you are looking for a covering index. A covering index (one that can satisfy the entire query without going to the table) only works if it contains the complete data. In your example, the index on filename
includes up to 255 characters. If the actual file name were longer, it would not contain the entire data, so it is not a covering index for that query.
If filename
had a type such as varchar(255)
, then it would use the index for the example query.