Answer the question
In order to leave comments, you need to log in
Why doesn't MySQL use indexes?
There is a table:
Indexes are created for it:
But when executing the query:
SELECT `place`.`id`, `place`.`root`, `place`.`lft`, `place`.`rgt`, `place`.`level`, `place`.`type`, `place`.`slug`, `place`.`latitude`, `place`.`longitude`, `place`.`time_zone_id`, `place`.`count_views`
FROM `my_geoservices`.`place`
WHERE `place`.`rgt` >= 29602 AND `place`.`root` = 2
Answer the question
In order to leave comments, you need to log in
A very common misconception is that if there is an index, then it is always used.
Nothing like this. Moreover, even in the same query, but with different data, the index may or may not be taken into account.
For example, we have a million records with a boolean field, and an index on it (nonsense, of course, but just right for an example). And out of this million, five records have true in this field, and the rest have false.
So, select * from table where boolField = true index is enabled, but select * from table where boolField = false is not. Because, from the point of view of the optimizer, it is justified to search first in the index and then in the table for five positions, but it is completely redundant to do almost the same work for 999,995 records.
This is, of course, on the fingers, but the meaning is something like this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question