mysql - 为什么数据库表 TABLES.table_rows 列与 MySQL 中物理表中的 select count(*) 不匹配

标签 mysql database count information-schema

将 information_schema.TABLES.table_rows 列与从“SELECT count(*) from ”检索到的物理行数进行比较时,数字不匹配。为什么行数不同?

mysql> select TABLE_ROWS from TABLES where TABLE_NAME = 'gbl_session' and TABLE_SCHEMA = 'mydb';
+------------+
| TABLE_ROWS |
+------------+
|       7306 |
+------------+
1 row in set (0.01 sec)

mysql> select count(*) from mydb.gbl_session;
+----------+
| count(*) |
+----------+
|     7800 |
+----------+
1 row in set (0.01 sec)

最佳答案

For InnoDB tables, the row count is only a rough estimate used in SQL optimization. (This is also true if the InnoDB table is partitioned.)

阅读此内容了解更多信息:https://dev.mysql.com/doc/refman/5.1/en/tables-table.html

正如那里的评论所建议的那样,您可以尝试:

TABLE_ROWS (and perhaps some other columns in INFORMATION_SCHEMA.TABLES) may get out of sync with the current table contents, but you can update it by running ANALYZE.

关于mysql - 为什么数据库表 TABLES.table_rows 列与 MySQL 中物理表中的 select count(*) 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31567817/

相关文章:

php - 如何根据date_time从数据库中按降序获取数据?

mysql - 保存时间大于24小时

c# - SignalR 和数据库上下文处理

MySQL:在其他表中计数

count - Netlogo 计数链接

excel - 选择整个最后一行

mysql - 如何在 jpa 和 PagingAndSortingRepository 中设置每页限制结果?

mysql - 使用 IF 语句进行查询

javascript - Couchbase、减少过大误差

mysql - 在单个查询中选择总行数、总字段 1 = 1、总字段 1 = 0?