开发者

MySQL command Explain ignore LIMIT?

开发者 https://www.devze.com 2023-03-21 19:11 出处:网络
I use MySQL server version 5.5.14 and now I am trying this simple SQL query with Explain command: EXPLAIN SELECT id, name, thumb FROM `twitter_profiles` LIMIT 10;

I use MySQL server version 5.5.14 and now I am trying this simple SQL query with Explain command:

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

and it 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 it scans whole table instead of taking the first 10 rows as I specified in LIMIT clause?


here a good link of article about MySQL EXPLAIN limits and errors

LIMIT is not taken into account while estimating number of rows Even if you have LIMIT which restricts how many rows will be examined MySQL will still print full number


You need to use order by:

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

精彩评论

暂无评论...
验证码 换一张
取 消