MySQL命令解释忽略LIMIT?
我使用MySQL服务器版本5.5.14,现在我正在尝试使用Explain命令进行这个简单的SQL查询:
EXPLAIN SELECT id, name, thumb FROM `twitter_profiles` LIMIT 10;
它向我显示了这个结果:
+----+-------------+-------+------+---------------+------+---------+------+-------+-------+
| 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)
我的问题是为什么它扫描整个表而不是像我在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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一个关于 MySQL EXPLAIN 限制和错误的文章的好链接
here a good link of article about MySQL EXPLAIN limits and errors
您需要使用 order by:
You need to use order by: