查询sql语句: select Name ,Id, count(*) from test where sesTime is not null group by Name order by count(*) desc limit 15; ############################ 查看sql语句的执行计划: desc select Name ,Id, count(*) from test where sesTime is not null group by Name order by count(*) desc limit 15;+----+-------------+----------------+------------+------+---------------+------+---------+------+---------+----------+----------------------------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+----------------+------------+------+---------------+------+---------+------+---------+----------+----------------------------------------------+ | 1 | SIMPLE | test | NULL | ALL | NULL | NULL | NULL | NULL | 1305648 | 90.00 | Using where; Using temporary; Using filesort | +----+-------------+----------------+------------+------+---------------+------+---------+------+---------+----------+----------------------------------------------+ 1 row in set, 1 warning (0.00 sec) Thu Oct 10 18:34:36 2019 显然,这是一个全表扫描语句, ########################## 查看该表的数据量: select count(*) from test; +----------+ | count(*) | +----------+ | 1373833 | +----------+ 1 row in set (0.48 sec) Thu Oct 10 18:45:10 2019 显然,该表数据量有140万条记录左右。 ############################ 查看该表结构: show create table mbi_order_temp\G; *************************** 1. row *************************** Thu Oct 10 18:48:10 2019
从这个表结构语句可知:分组字段fiveGradeName没有索引,因此整个语句都是全表扫描
#######
#######
原文:https://www.cnblogs.com/igoodful/p/11649935.html