如果我发出以下命令:
CREATE TABLE foo LIKE bar;
INSERT INTO bar SELECT * FROM foo;
foo 中有几百万行,因此此操作需要一些时间。
如果我在执行上面的过程中重复执行以下查询:
use information_schema
select table_name, TABLE_ROWS from tables where table_name IN ('foo','bar');
我看到了以下进展:
+---------------------------------+------------+
| table_name | TABLE_ROWS |
+---------------------------------+------------+
| foo | 21270328 |
| bar | 5292482 |
+---------------------------------+------------+
稍后:
+---------------------------------+------------+
| table_name | TABLE_ROWS |
+---------------------------------+------------+
| foo | 21270328 |
| bar | 3422182 |
+---------------------------------+------------+
为什么这个数字会减少?
最佳答案
如 information_schema.tables 的文档中所述,“对于 InnoDB 表,行数只是 SQL 优化中使用的粗略估计。”
关于MySQL TABLE.TABLE_ROWS 在插入期间减少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8234693/