首页 > 其他 > 详细

大表查询必须使用索引

时间:2019-10-10 19:39:23      阅读:104      评论:0      收藏:0      [点我收藏+]

 

 

查询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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!