MySQL command Explain to ignore LIMIT?

I am using mySQL server version 5.5.14, and now I am trying to execute this simple SQL query using the Explanation command:

EXPLAIN SELECT id, name, thumb FROM `twitter_profiles` LIMIT 10; 

and he shows me this result:

 +----+-------------+-------+------+---------------+------+---------+------+-------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+-------+-------+ | 1 | SIMPLE | tp | ALL | NULL | NULL | NULL | NULL | 40823 | | +----+-------------+-------+------+---------------+------+---------+------+-------+-------+ 1 row in set (0.02 sec) 

My question is why does it scan the entire table instead of taking the first 10 rows, as I pointed out in the LIMIT clause?

Thanks for your advice in advance!

Greetings

Jakub

+6
source share
2 answers

here is a good article link about MySQL EXPLAIN Limitations and Errors

LIMIT is not taken into account when evaluating the number of lines. Even if you have a LIMIT that limits the number of lines to be checked, MySQL will still print the full number

+10
source

you need to use order ..

 EXPLAIN SELECT id, name, thumb FROM twitter_profiles ORDER BY LIMIT 10; 

Hope this helps you.

-3
source

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


All Articles