有一个数据库,表中的数据根据bingint类型的数据匹配查询,还是特别慢,一个查询要1~2秒 首先看下数据总量
SELECT count(*) FROM wxf_prevention_vice
> count(*)
2390204
总数两百多万,mysql数据量在500W以内问题都不大,不应该这么慢。 使用***EXPLAIN***分析
EXPLAIN SELECT * FROM wxf_prevention_vice WHERE preventionid = '1247776189100986369';
> id select_type table partitions type Possible_keys
i SIMPLE wxf_prevention_vice (null) ALL (null)
>key key_len ref rows filtered Extra
(null) (null) (null) 198449 10.00 Using where
根据分析结果,决定增加索引,查看增加索引后的效果
EXPLAIN SELECT * FROM wxf_prevention_vice WHERE preventionid = '1247776189100986369';
id select_type table partitions type Possible_keys
1 SIMPLE wxf_prevention_vice (null) ref preventionid_index
>key key_len ref rows filtered Extra
preventionid_index 9 const 41 100.00 Using index condition
注意:本文归作者所有,未经作者允许,不得转载