Does MySQL not use index on DATE when using '<' or '>' operators?

I use the explanation to verify these requests. Type col - DATE

index used:

explain SELECT events.* FROM events WHERE events.date = '2010-06-11' 

is not

explain SELECT events.* FROM events WHERE events.date >= '2010-06-11' 

as follows (phpmyadmin)

Action  Keyname Type    Unique  Packed  Field   Cardinality Collation   Null    Comment
Edit    Drop    PRIMARY BTREE   Yes No  event_id    18  A       
Edit    Drop    date    BTREE   No  No  date    0   A       

i it can be seen that the power is 0, although there are several rows with the same date.

+3
source share
1 answer

If MySQL does not use an index, he saw your query and appreciated that scanning the table is likely to be faster than using the index (depending on IO / disk operations, it may be required). You can use FORCE INDEXand check whether this query will actually be faster using the index or not.

SELECT events.* FROM events
FORCE INDEX (date)
WHERE events.date >= '2010-06-11';
+6
source

Source: https://habr.com/ru/post/1750645/


All Articles