will show table status display exact rows in the table?

▼魔方 西西 提交于 2020-01-30 08:39:07

问题


I have a table in DB and it is approx 90 GB in space. I tried to count no of rows in the table select count(idNewsNotification) from notification and it resulted

4982397

1 row in set (59 min 48.35 sec)

But when I queried using show table status like <table_name> it is showing that

 Engine: InnoDB
 Version: 10
 Row_format: Compact
 Rows: 8631267
 Avg_row_length: 11237
 Data_length: 96996425728
 Max_data_length: 0
 Index_length: 175374336
 Data_free: 0
 Auto_increment: NULL
 .....

What is the perfect procedure for knowing the no of records in the table ?


回答1:


The fact that your count took an hour implies that you're running InnoDB (which doesn't cache this data).

As such, the table status is an approximation based on other factors, and is not to be trusted.

The count(*) would be accurate, but a pain to wait for.

From the doc:

Some storage engines, such as MyISAM, store the exact count. For other storage engines, such as InnoDB, this value is an approximation, and may vary from the actual value by as much as 40 to 50%. In such cases, use SELECT COUNT(*) to obtain an accurate count.




回答2:


This is not a good one, in some cases.

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.)

TEST:

I have the same db (dumped and imported on different server) both innoDB

Same table:

Server One: 49,231
Server Two: 53,242

49231 is not correct and You can see this table with "~" mark in phpmyadmin



来源:https://stackoverflow.com/questions/12966538/will-show-table-status-display-exact-rows-in-the-table

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