本文介绍了MySQL的行数count(*)与information_schema中的table.table_rows不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个奇怪的现象,我希望有人可以向我解释一下:

我有一些静态"表格(每天更改一次).

mysql> select 'appObjectGroups' as tbl, count(*) as num from appObjectGroups
  union select 'appObjectDependencies' as tbl, count(*) as num from appObjectDependencies
  union select 'appObjectUrls' as tbl, count(*) as num from appObjectUrls 
  union select 'appObjectValues' as tbl, count(*) as num from appObjectValues 
  union select 'appObjects;' as tbl, count(*) as num from appObjects;
+-------------------------+------+
| tbl                     | num  |
+-------------------------+------+
| appObjectGroups         | 1149 |
| appObjectDependencies   | 6885 |
| appObjectUrls           | 1162 |
| appObjectValues         | 3795 |
| appObjects;             | 5409 |
+-------------------------+------+
5 rows in set (0.00 sec)

mysql> select table_name as tbl, table_rows as num from information_schema.tables where table_schema='mySchema' and table_name like 'app%';
+-------------------------+------+
| tbl                     | num  |
+-------------------------+------+
| appObjectGroups         | 1141 |
| appObjectDependencies   | 6153 |
| appObjectUrls           | 1141 |
| appObjectValues         | 3584 |
| appObjects              | 6061 |
+-------------------------+------+
5 rows in set (0.01 sec)

那么table_rows为何报告与count(*)不同的内容?

对我来说更重要的是:哪一个是正确的? :-)

解决方案

文档:

i came across a strange phenomenon, and i hope, that someone can explain this to me:

i have a some "static" tables (they change once per day).

mysql> select 'appObjectGroups' as tbl, count(*) as num from appObjectGroups
  union select 'appObjectDependencies' as tbl, count(*) as num from appObjectDependencies
  union select 'appObjectUrls' as tbl, count(*) as num from appObjectUrls 
  union select 'appObjectValues' as tbl, count(*) as num from appObjectValues 
  union select 'appObjects;' as tbl, count(*) as num from appObjects;
+-------------------------+------+
| tbl                     | num  |
+-------------------------+------+
| appObjectGroups         | 1149 |
| appObjectDependencies   | 6885 |
| appObjectUrls           | 1162 |
| appObjectValues         | 3795 |
| appObjects;             | 5409 |
+-------------------------+------+
5 rows in set (0.00 sec)

mysql> select table_name as tbl, table_rows as num from information_schema.tables where table_schema='mySchema' and table_name like 'app%';
+-------------------------+------+
| tbl                     | num  |
+-------------------------+------+
| appObjectGroups         | 1141 |
| appObjectDependencies   | 6153 |
| appObjectUrls           | 1141 |
| appObjectValues         | 3584 |
| appObjects              | 6061 |
+-------------------------+------+
5 rows in set (0.01 sec)

so how come that table_rows report something different than count(*)?

and more important to me: which one is correct? :-)

解决方案

Quoting from documentation:

这篇关于MySQL的行数count(*)与information_schema中的table.table_rows不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 04:23