select_type

  • SIMPLE:没有union和子查询
  • PRIMARY:主查询
  • UNION:UNION或UNION ALL 的子查询
  • UNION RESULT:UNION去重
    • image.png
  • SUBQUERY:不相关子查询【只执行一次】
    • image.png
  • DEPENDENT SUBQUERY:相关子查询(不能转为半连接)【可能执行多次】
    • image.png
  • DEPENDENT UNION:相关子查询中的UNION?
    • image.png
  • DERIVED:子查询物化
    • image.png
  • MATERIALIZED:子查询物化之后,连接查询

    • 去重建立唯一索引?所以物化?
    • image.png

      type

      单表查询

  • system

    • 表中一行 or 空表
  • const【就是因为使用自适应hash?】
    • 主键、唯一索引
  • ref
    • 普通索引 = x
    • 主键 is null
  • ref_or_null
    • 普通索引 is null
  • range
    • 普通索引 > x
  • index
    • 遍历普通索引的叶子节点,且普通索引上有数据,不需要回表。
    • order by主键,也是index。
    • 排序的情况下,性能比all高

  • index_merge:索引合并

    • image.png

      关联查询

  • eq_ref

    • 被驱动表:主键、唯一索引
  • ref
    • 非唯一关联:SELECT * FROM ref_table,other_table WHERE ref_table.key_column=other_table.column;

rows和filtered

  • rows:扫描行数
  • filtered:预估满足条件的有多少

    using index condition 【索引下推】和using where; Using index的区别

    using condition index和using where,using index区别

    using join buffer(Block Nested loop)

    Join

    using MRR【主键排序后批量回表】

    Join

    using filesort & using temporary

    using filesort & using temporary

    Handlerread*

    SHOW SESSION STATUS LIKE ‘Handler_read%’;

  • Handler_read_first:全索引扫描,The number of times the first entry was read from an index.

  • Handler_read_key:好,read row based on key
  • Handler_read_next:按索引顺序取数据,The number of requests to read the next row in key order
  • Handler_read_prev:desc,索引倒序
  • Handler_read_rnd:The number of requests to read a row based on a fixed position.
  • Handler_read_rnd_next :没有索引

MySQL执行SHOW STATUS查询服务器状态状态之Handlerread* 详解 - yuyue2014 - 博客园

EXPLAIN FORMAT=tree

image.png

using index for skip scan :松散索引扫描【8.0】