Can I force MySQL to use an index?

前端 未结 2 853
不思量自难忘°
不思量自难忘° 2021-01-16 05:39

I created a table which has close to 800,000 records.

mysql> describe automation_search_test;
+----------+---------+------+-----+---------+---------------         


        
相关标签:
2条回答
  • 2021-01-16 05:56

    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.

    0 讨论(0)
  • 2021-01-16 06:16

    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.

    0 讨论(0)
提交回复
热议问题