EXPLAIN and COUNT returning two different values(EXPLAIN 和 COUNT 返回两个不同的值)
问题描述
我在做:
explain select * from calibration;
它说 52133456345632 行
it says 52133456345632 rows
当我这样做时:
select count(*) from calibration;
我收到了 52134563456961
i am getting 52134563456961
有人能解释一下这里发生了什么吗?
can someone explain whats going on here?
推荐答案
表统计信息(由 EXPLAIN 使用)基于系统缓存的值,可能不准确.
Table statistics (used by EXPLAIN) are based on system-cached values that may not be accurate.
http://dev.mysql.com/doc/refman/5.1/en/using-explain.html 说:
对于 InnoDB 表,这个数字是一个估计值,可能并不总是准确的.
For InnoDB tables, this number is an estimate, and may not always be exact.
因此,'count()' 版本的查询将是准确的,因为它确实会计算"现有行.解释"版本不一定计算您的行数,但可能会使用估计/缓存.解释并不打算在代码或生产中实际使用 - 它只是帮助分析查询的工具.
So the 'count()' version of the query will be accurate, as it will really 'count' existing rows. The 'explain' version does not necessarily count your rows, but might use an estimation/cache. Explain is not intended to be actually used in code or production - it is just a tool to help analysing your queries.
这篇关于EXPLAIN 和 COUNT 返回两个不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:EXPLAIN 和 COUNT 返回两个不同的值


基础教程推荐
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01