Why the rows returns by quot;explainquot; is not equal to count()?(为什么行通过“解释返回?不等于count()?)
问题描述
mysql> select count(*) from table where relation_title="eHh4eHh4eHh4";
+----------+
| count(*) |
+----------+
| 1291958 |
+----------+
mysql> explain select * from table where relation_title="eHh4eHh4eHh4";
+----+-------------+---------+-
| id | select_type | rows |
+----+-------------+---------+-
| 1 | SIMPLE | 1274785 |
+----+-------------+---------+-
我认为解释 select * from table where relationship_title="eHh4eHh4eHh4";"按索引返回relation_title="eHh4eHh4eHh4" 的行.但它比真正的数字小.
I think that "explain select * from table where relation_title="eHh4eHh4eHh4";" returns the rows of relation_title="eHh4eHh4eHh4" by index. But it's small than the true num.
推荐答案
它显示了它运行了多少行以获得您的结果.
It is showing how many rows it ran through to get your result.
错误数据的原因是 EXPLAIN 不准确,它根据存储的有关您的表的信息对您的数据进行猜测.
The reason for the wrong data is that EXPLAIN is not accurate, it makes guesses about your data based on information stored about your table.
这是非常有用的信息,例如在对许多表执行 JOINS 时,您希望确保不会为每一行的一行信息遍历整个连接表.
This is very useful information, for example when doing JOINS on many tables and you want to be sure that you aren't running through the entire joined table for one row of information for each row you have.
这是对 608 行表的测试.
Here's a test on a 608 row table.
SELECT COUNT(id) FROM table WHERE user_id = 1
结果:
COUNT(id)
512
这里是解释
EXPLAIN SELECT COUNT(id) FROM table WHERE user_id = 1
结果:
id rows
1 608
这篇关于为什么行通过“解释"返回?不等于count()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么行通过“解释"返回?不等于count()?


- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- SQL 临时表问题 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01