MySQL命令解释忽略LIMIT吗? [英] MySQL command Explain ignore LIMIT?

查看:147
本文介绍了MySQL命令解释忽略LIMIT吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是MySQL服务器版本5.5.14,现在我正在尝试使用Explain命令进行此简单的SQL查询:

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;

它向我显示了此结果:

+----+-------------+-------+------+---------------+------+---------+------+-------+-------+
| 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行?

My question is why it scans whole table instead of taking the first 10 rows as I specified in LIMIT clause?

推荐答案

此处是有关 估计行数时不考虑

LIMIT偶数 如果您有LIMIT来限制要检查的行数MySQL 仍会打印完整号码

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

这篇关于MySQL命令解释忽略LIMIT吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆