Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 信息架构中表行数的差异_Mysql_Mariadb - Fatal编程技术网

Mysql 信息架构中表行数的差异

Mysql 信息架构中表行数的差异,mysql,mariadb,Mysql,Mariadb,当我使用查询对表进行计数时,信息\方案表如何显示不同的信息行: select count(id) from mytable 另一个查询: SELECT engine AS Engine, table_name AS Table, table_rows AS Rows, round(((data_length + index_length) / 1024 / 1024), 2) as Size FROM information_schema.TABLE

当我使用查询对表进行计数时,信息\方案表如何显示不同的信息行:

select count(id) from mytable
另一个查询:

SELECT 

   engine AS Engine, 
   table_name AS Table, 
   table_rows AS Rows, 
   round(((data_length + index_length) / 1024 / 1024), 2) as Size

FROM

   information_schema.TABLES

WHERE

   table_schema = DATABASE()

ORDER BY 

   Size desc;
我的数据库版本:10.1.33-MariaDB


谢谢你的建议

第一个查询返回正确的值

第二个查询从
information\u schema.TABLES
中获取值,用于存储每个表的统计信息。此表的要点是帮助MySQL查询优化器选择最佳执行计划


因此,数量级应该是正确的,但不能使用此表获得准确的行数。

不需要解决方案。如果需要准确的行数,请使用第一个查询。除了粗略估计行计数的数量级之外,不应该使用第二个查询。只要没有查询优化器问题,就不必担心这两个值之间的差异。如果要更新估计值,可以运行
analyze table mytable
,但请注意,您无论如何都不会得到准确的值,因为只有表的一个样本用于执行估计值。(这是一个dup问题。)“问题”适用于InnoDB表。