在 MySQL 中获取表的行数?

Getting row count for a table in MySQL?(在 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_SCHEMATABLE表中查找行数?

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 中获取表的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)