gpt4 book ai didi

mysql - 慢速 SELECT COUNT(*)、information_schema、基数字段

转载 作者:行者123 更新时间:2023-11-29 14:15:42 25 4
gpt4 key购买 nike

我有一个很大的表(60+ 数百万条记录)。该表有主键(id、auto_increment、索引id)

我有一个从此表中选择记录的报告。为了浏览和导航此报告(用 PHP 编写),我使用分页脚本。

该脚本使用 SELECT COUNT() 来获取该表中的记录总数。SELECT COUNT() 非常慢。

问题:我可以查询统计表中的基数字段,information_schema DB,其中 table_name = my_large_table_name 和 column_name = id 和(或)index_name 是我的 auto_incremented id 的索引名称,然后将结果用作分页脚本中的总行数? p>

更新:

或者我可以查询 information_schema 中的表 TABLES 中的 TABLE_ROWS 字段,以获取表中的总行数吗?结果准确吗?

该表使用InnoDB引擎。

最佳答案

听起来像一个 innodb 表,其中行数没有缓存,因此必须计算。

表格统计数据也可能不准确:

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%. http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html

你见过SQL_CALC_FOUND_ROWS吗? http://dev.mysql.com/doc/refman/5.0/en/information-functions.html

关于mysql - 慢速 SELECT COUNT(*)、information_schema、基数字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12736350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com