• mysql执行计划 const eq_ref ref range index all 关键词解释


    explain:查询查询性能或者需要查看使用索引状态

    一、type:连接类型  最关键的一列  效率(const>eq_ref>ref>range>index>all)

    1、const:查询索引字段,并且表中最多只有一行匹配(好像只有主键查询只匹配一行才会是const,有些情况唯一索引匹配一行会是ref)

    2、eq_ref    主键或者唯一索引  

    3、ref   非唯一索引(主键也是唯一索引)

    4、range  索引的范围查询

    5、index  (type=index extra = using index 代表索引覆盖,即不需要回表)

    6、all 全表扫描(通常没有建索引的列)

    二、key_len

    索引的长度,在不损失精度的情况下越短越好

    三、ref

    四、rows (内循环的次数)

    五、extra

    重要的几个

    1、using temporary(组合查询返回的数据量太大需要建立一个临时表存储数据,出现这个sql应该优化)

    2、using where (where查询条件)

    3、using index(判断是否仅使用索引查询,使用索引树并且不需要回表查询)

    4、using filesort(order by 太占内存,使用文件排序)

    了解的几个

    1、const row not found(据说是当表为空的时候展示,我用了个空表explain之后发现extra列是空值)

    2、deleting all rows (MYISAM存储引擎快速清空表)

    3、first_match(select * from a where name in(select a_name from B) ,B中有n条记录都记录了同一个a_name,每个a_name都只会匹配一次。exist也有同样的效果)

    4、impossible having, impssible where  (错误的having 和where如,where 1<0)

    5、Impossible WHERE noticed after reading const tables(如 where id =1 and name = "temp",表中不存在id=1并且name=temp的记录)

    附带一个详细的extra链接:https://blog.csdn.net/poxiaonie/article/details/77757471

  • 相关阅读:
    虚继承virtual public
    My first blog
    mybatis(一)SqlSessionFactory初始化
    dubbo
    设计模式
    基本算法
    redis
    spring cloud eureka
    spring boot
    spring MVC
  • 原文地址:https://www.cnblogs.com/ningwuyu/p/16145343.html
Copyright © 2020-2023  润新知