标签:分享 根据 title cost _id des 隐式转换 cat img
explain select * from actor where last_name like ‘%NI%‘\G;
explain select * from actor where last_name like ‘NI%‘\G;
先扫描索引 last_name获取满足条件的%NI%的主键actor_id列表,之后根据主键回表去检索记录,这样访问避开了全表扫描actor表产生的大量IO请求。
explain select * from (select actor_id from actor where last_name like ‘%NI%‘) a,actor b where a.actor_id = b.actor_id\G;
explain select * from actor where last_name=1\G;
explain select * from actor where last_name=‘1‘\G;
explain select * from payment where amount=3.98 and last_update=‘2016-02-15 22:12:32‘\G;
update film_text set title =concat(‘S‘,title);
explain select * from film_text where title like ‘S%‘\G;
可以看出全表扫描需要访问的记录rows为1000,代价cost计算为233.53;
通过idx_title_desc_part索引扫描访问记录rows为998,代价cost为1198.6 要高于全表扫描的时间,mysql会选择全表扫描
用or分割开的条件,or前条件有索引,or后的列没有索引,那么涉及的索引不会被用到
因为or后面的条件没有索引,那么后面的查询肯定要进行全表扫描,在存在全表扫描的情况下,就没有必要多一次索引扫描增加IO访问。
explain select * from payment where customer_id =203 or amount=3.96\G;
标签:分享 根据 title cost _id des 隐式转换 cat img
原文地址:http://www.cnblogs.com/dsitn/p/7091283.html