select arrival_record操作记录的慢查询数量最多有4万多次,平均响应时间为4s,delete
arrival_record记录了6次,平均响应时间258s
select xxx_record语句
select arrival_record 慢查询语句都类似于如下所示,where语句中的参数字
段是一样的,传入的参数值不一样
select count(*) from arrival_record where product_id=26 and
receive_time between '2019-03-25 14:00:00' and '2019-03-25 15:00:00'
and receive_spend_ms>=0\G
select arrival_record 语句在mysql中最多扫描的行数为5600万、平均扫描的行数为172万,
推断由于扫描的行数多导致的执行时间长
查看执行计划
explain select count(*) from arrival_record where product_id=26 and
receive_time between '2019-03-25 14:00:00' and '2019-03-25 15:00:00'
and receive_spend_ms>=0\G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: arrival_record
partitions: NULL
type: ref
possible_keys: IXFK_arrival_record
key: IXFK_arrival_record
key_len: 8
ref: const
rows: 32261320
filtered: 3.70
Extra: Using index condition; Using where
1 row in set, 1 warning (0.00 sec)
用到了索引IXFK_arrival_record,但预计扫描的行数很多有3000多w行
show index from arrival_record;
+----------------+------------+---------------------+--------------+------
--------+-----------+-------------+----------+--------+------+------------
+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name |
Collation | Cardinality | Sub_part | Packed | Null | Index_type |
Comment | Index_comment |
+----------------+------------+---------------------+--------------+------
--------+-----------+-------------+----------+--------+------+------------
+---------+---------------+
| arrival_record | 0 | PRIMARY | 1 | id | A | 107990720 | NULL | NULL | |
BTREE | | |
评论