执行计划的分析

2019-07-20  本文已影响0人  蔺蔺蔺赫赫

执行计划的分析

主要是看

mysql> desc select * from oldboy.t100w where k2='EF12'\G

                id : 1

  select_type : SIMPLE

          table : t100w

    partitions : NULL

          type : ref

possible_keys : idx_k2

            key : idx_k2

      key_len : 17

              ref : const

          rows : 293

        filtered : 100.00

          Extra : NULL

1 row in set, 1 warning (0.00 sec)

          table: t100w

            type: ref            索引的应用级别

possible_keys: idx_k2  可能会使用到的索引 

              key: idx_k2 实际上使用的索引

        key_len: 17 联合索引覆盖长度

            rows: 293 查询的行数(越少越好)

            Extra: NULL    额外的信息

type  索引的应用级别

ALL : 全表扫描不走索引

不走索引的情况

没建立索引!!

建立索引不走的()!!!!

mysql> desc select * from t100w;

mysql> desc select * from t100w where k1='aa';

mysql> desc select * from t100w where k2 != 'aaaa';

mysql> desc select * from t100w where k2 like '%xt%';

Index :全索引扫描

mysql> desc select k2 from t100w;

range :索引范围扫描

辅助索引 : > < >= <= like ,  in  or    主键: !=

mysql> desc select * from world.city where countrycode like 'C%'

mysql> desc select * from world.city where id!=3000;

mysql> desc select * from world.city where id>3000;

mysql> desc select * from world.city where countrycode in ('CHN','USA');

改写为等值扫描

desc

select * from world.city where countrycode='CHN'

union all

select * from world.city where countrycode='USA';

ref : 辅助索引等值查询

mysql> desc select * from city where countrycode='CHN';

eq_ref :在多表连接查询时on的条件列是唯一索引或主键

mysql> desc select city.name,country.name ,country.surfacearea

from city

join country

on city.countrycode=country.code

where city.population <100;

const,system : 主键或唯一键等值查询

mysql> DESC SELECT * from city where id=10;

上一篇 下一篇

猜你喜欢

热点阅读