mysql数据量太大, count(*)无法查询总数

表数据6千万左右, 查询count(*),count(1)查询超时, 无法查询总数

方法1: 使用Explain查询

EXPLAIN SELECT count(*) FROM bp_account_role;

expain出来的信息有10列,分别是id、select_type、table、type、possible_keys、key、key_len、ref、rows、Extra

概要描述:
id:选择标识符
select_type:表示查询的类型。
table:输出结果集的表
partitions:匹配的分区
type:表示表的连接类型
possible_keys:表示查询时,可能使用的索引
key:表示实际使用的索引
key_len:索引字段的长度
ref:列与索引的比较
rows:扫描出的行数(估算的行数)
filtered:按表条件过滤的行百分比
Extra:执行情况的描述和说明

rows: 估算出结果集行数,表示MySQL根据表统计信息及索引选用情况,估算的找到所需的记录所需要读取的行数

方法2:通过查看所数据库各表容量大小, 查询总数

select
table_schema as '数据库',
table_name as '表名',
table_rows as '记录数',
truncate(data_length/1024/1024, 2) as '数据容量(MB)',
truncate(index_length/1024/1024, 2) as '索引容量(MB)'
from information_schema.tables
where table_schema='uupmya'
order by data_length desc, index_length desc;

扫描二维码关注公众号,回复: 15848173 查看本文章

猜你喜欢

转载自blog.csdn.net/bugua3542/article/details/120698878
今日推荐