K
K
KarambiG2021-07-15 15:29:19
MySQL
KarambiG, 2021-07-15 15:29:19

Why is mySQL running unpredictably?

I will give an example: and the table has 800 thousand lines.
SELECT * FROM `users` WHERE age = 27
SELECT * FROM `users` WHERE age >= 27

Since there is no key in the age field, it will iterate over ALL 800 thousand rows in order. EXPLAIN proves it.
But what's interesting.
First select: (11269 total, Query took 0.0024 sec.)
Second select: (597449 total, Query took 0.0003 sec.)

SUMMARY: First select was 8 times slower!
Even if you make more complex queries, then the same topic. Recently I made a complicated request.
In the first case (=) the query took 0.02 seconds, and in the second case (>=) the query took 0.0005 seconds.

Why is this happening? what mystic?)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question