Getting row count for a table in MySQL?(在 MySQL 中获取表的行数?)
问题描述
谁能告诉我在查找表的行数时,他在 MySQL 中使用哪种方法更好:这样做更好吗
Can anyone tell me which is he better appraoch in MySQL whin it comes to finding the row count of a table: is it better to do
SELECT COUNT(*) FROM TABLE_NAME
还是在INFORMATION_SCHEMA的TABLE表中查找行数?
or to look up the row count in the table TABLE in the INFORMATION_SCHEMA?
这会是计算页面分页计数的常用操作吗?
This would be a frequent operation for calculating pagination counts for pages?
我应该补充一点,表格最多只有几千行.
I should add that tables will only have a few thousand rows at most.
谢谢
马丁·奥谢.
推荐答案
在MyISAM中,这个查询:
SELECT COUNT(*)
FROM TABLE_NAME
是即时的,因为它保存在表元数据中,所以几乎可以自由地发出这个查询,并且它总是会得到正确的结果.
is instant, since it's kept in the table metadata, so it's almost free to issue this query and it will always get the correct result.
在 InnoDB 中,此查询将一一计算行数,这可能需要一些时间.
In InnoDB, this query will count rows one-by-one which could take some time.
所以如果你不需要COUNT(*)的精确值,你可以查询INFORMATION_SCHEMA.
So if you don't need exact value of COUNT(*), you may query INFORMATION_SCHEMA.
这篇关于在 MySQL 中获取表的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 MySQL 中获取表的行数?
基础教程推荐
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 在多列上分布任意行 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
