实测MySQL索引

先附上三个表结构   vote_record           group            status


测试查询多条数据

select *

from vote_record

left join `group` on vote_record.group_id=`group`.type
left join `status` on vote_record.`status`=`status`.type
where user_id like '%1%' order by vote_record.id desc


8.412秒





查询单条数据

select *
from vote_record
left join `group` on vote_record.group_id=`group`.type
left join `status` on vote_record.`status`=`status`.type
where user_id = '6CC5oAA19y9W5rPDvsEI' order by vote_record.id desc


加索引前   0.307秒


创建索引  

CREATE INDEX index_uid ON vote_record (user_id)


加索引后   0.006秒



CREATE INDEX index_gid ON `group` (type)
CREATE INDEX index_sid ON `status` (type)


加完这两个索引后   0.004秒



explain select * from tb_test ; 关注的项目

type:查询access的方式 key:本次查询最终选择使用哪个索引,NULL为未使用索引 key_len:选择的索引使用的前缀长度或者整个长度 rows:可以理解为查询逻辑读,需要扫描过的记录行数 extra:额外信息,主要指的fetch data的具体方式



猜你喜欢

转载自blog.csdn.net/qq_30986969/article/details/80581549