Mysql inconsistent number of rows count(*) vs table.table_rows in information_schema

不羁的心 提交于 2019-12-20 05:52:08

问题


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? :-)


回答1:


Quoting from documentation:

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://stackoverflow.com/questions/34003036/mysql-inconsistent-number-of-rows-count-vs-table-table-rows-in-information-sc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!