Mysql employees test database employees table. Why is it that after indexing hire_date, a full table scan is performed?

Test database downloaded on github.

Index:
clipboard.png

explain select:
clipboard.png

query the scope of the date field of the employees table if you want to query the recruits in a certain period of time,
1. Why interpret the results, using the type field or ALL? What does the index in
2.possible_keys mean?
3. Is it the sql problem or the index problem? How should I change it?

can you give me some advice? no, no, no.


1. Because you need to return to the table after you have checked the index. The optimizer thinks that it is not as expensive to return to the table as directly traversing the whole table
2. Literally, it means the index
3 that may be used. Depending on your business requirements, for example, you only need to return a few fields instead of all, consider using an overlay index. You can also force index, force the index to see if the index is fast or full table scan is fast (the optimizer may misjudge). If the index is fast, you can force the index


your hire_date field type is not appropriate, is it a string type?

where hire_date > implicitly converts the hire_date, causing the index to fail.

hire_date can be set to type date.

Menu