1.select_type:

/* select_type 使用 SIMPLE */
explain select * from tb_shop_order where id='20160329257032899';

/* select_type 使用 PRIMARY --最外面的select
  select_type 使用 SUBQUERY  --子查询第一个select
 */
explain  select gorder_id,order_time from tb_shop_order  where order_time = (select max(order_time) from tb_shop_order);

/*select_type 使用UNION 和 UNION RESULT*/
explain select * from tb_shop_order where order_time='2015-04-27 11:41:46' union select * from tb_shop_order where order_time='2015-04-27 11:41:47' ;

/*select_type 使用 DEPENDENT SUBQUERY 表示子查询中的第一个SELECT,取决于外面的查询 */
explain select * from tb_shop_order a  where a.id in (select b.id from tb_shop_order b where  b.gorder_id='785948');

2.type
/*type 使用ref和 eq_ref */
explain select * from tb_shop_order a left join tb_shop_gorder b  on a.`gorder_id`= b.id  where  a. product_type='0701';

/*  type使用system --效率最好,表示表只有一行记录*/
explain select * from tb_shop_gorder_sequence where stub='a';

/*  type 使用const */
explain select * from tb_shop_order where id='20160329257032899';

/*  type 使用 index */
explain select gorder_id from tb_shop_order;
explain select * from tb_shop_order order by id desc;
explain  select merchant_id,avg(pay_amount) from tb_shop_order group by merchant_id order by avg(pay_amount) desc;

/*  type 使用range,检索给定范围的行,需要使用一个索引的字段来筛选 */
explain select * from tb_shop_order where order_time between '2015-01-01 00:00:00' and '2015-05-01 00:00:00';
explain select * from elong_ihotel_activity.`tb_ihotel_activity_detail` t  where t.`coupon_code` in ('TEST1234','NB123456');

/*type 使用DERIVED == 当子查询是from子句时 */
explain select * from  ( select merchant_id,merchant_name,avg(pay_amount) from tb_shop_order group by merchant_id,merchant_name order by avg(pay_amount) desc)  as table1 limit 2;

/*type 使用ref_or_null merchant_order_id 是一个空字段,并对该字段创建了一个索引,在下面的查询中可以看到联接类型为ref_or_null,
这是mysql为含有null的字段专门做的处理。在我们的表设计中应当尽量避免索引字段为NULL,因为这会额外的耗费mysql的处理时间来做优化。 */
explain select * from tb_shop_order where merchant_order_id ='2016666666666666' or merchant_order_id is null;

/*type 使用index_merge 表示使用了索引合并 */
explain  select * from tb_shop_order where merchant_order_id ='2016666666666666' or gorder_id ='784736';

/*type 使用unique_subquery
unique_subquery是一个索引查找函数,可以完全替换子查询,效率更高。
该类型替换了下面形式的IN子查询的ref: value IN (SELECT primary_key FROM single_table WHERE some_expr) */
explain select * from tb_shop_order a  where a.id in (select b.id from tb_shop_order b where  b.gorder_id='785948');

/*type 使用index_subquery
该联接类型类似于unique_subquery。可以替换IN子查询,但只适合下列形式的子查询中的非唯一索引:
value IN (SELECT key_column FROM single_table WHERE some_expr)该类型替换了下面形式的IN子查询的ref: value IN  */
explain select * from tb_shop_order a  where a.gorder_id in (select b.gorder_id from tb_shop_order b where  b.`buy_account_id`='190000032101145811');

3.extra

/*extra 使用 Select tables optimized away */
explain select max(gorder_id) from tb_shop_order;

/*extra 使用 Select tables optimized away */
explain select max(id) from tb_shop_order;

/*extra 使用 Using index   */
explain select count(*) from tb_shop_order;
explain select gorder_id from tb_shop_order;

/*extra 使用 Using union(ix_order_moid,ix_order_gorder_id); Using where */
explain  select * from tb_shop_order where merchant_order_id ='2016666666666666' or gorder_id ='784736';

/*extra 使用Using temporary; --为了解决查询,MySQL需要创建一个临时表来容纳结果。
 Using filesort  --MySQL需要额外的一次传递,以找出如何按排序顺序检索行。*/
explain  select merchant_id,avg(pay_amount) from tb_shop_order group by merchant_id order by avg(pay_amount) desc;

/*Using filesort*/
explain select * from tb_shop_order order by order_time desc;

/*extra Using index for group-by :表明可以在索引中找到分组所需的所有数据,不需要查询实际的表。*/
explain select buy_account_id from tb_shop_order t group by t.`buy_account_id`;

http://dev.mysql.com/doc/refman/5.5/en/explain-output.html#explain-extra-information  --官方文档

http://ustb80.blog.51cto.com/6139482/1064261  --执行计划参考

mysql中explain的更多相关文章

  1. mysql中explain的用法

    mysql中explain的用法 最近在做性能测试中经常遇到一些数据库的问题,通常使用慢查询日志可以找到执行效果比较差的sql,但是仅仅找到这些sql是不行的,我们需要协助开发人员分析问题所在,这就经 ...

  2. 详解MySQL中EXPLAIN解释命令

    Explain 结果解读与实践   基于 MySQL 5.0.67 ,存储引擎 MyISAM .   注:单独一行的"%%"及"`"表示分隔内容,就象分开“第一 ...

  3. MySQL中EXPLAIN解释命令详解

    MySQL中的explain命令显示了mysql如何使用索引来处理select语句以及连接表.explain显示的信息可以帮助选择更好的索引和写出更优化的查询语句. 1.EXPLAIN的使用方法:在s ...

  4. Mysql中explain命令查看语句执行概况

    Mysql中可以使用explain命令查看查询语句的执行方式,使用方法举例:explain + 查询语句 例如:explain select * from user_info 几个重要的字段说明: t ...

  5. MySQL中EXPLAIN解释命令 查看索引是否生效

    explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上explain就可以了: 如: expla ...

  6. MySQL中explain语句的使用

    一.概述 在 MySQL 中,我们可以使用慢查询日志或者 show processlist 命令等方式定位到执行耗时较长的 SQL 语句,在这之后我们可以通过 EXPLAIN或者 DESC 命令获取 ...

  7. MySQL中EXPLAIN命令详解

    explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上explain就可以了: 如: expla ...

  8. MySQL中EXPLAIN的解释

    EXPLAIN是查看MySQL优化器如何决定执行查询的主要方法,这个功能具有局限性,以为它并总是会说出真相,但是却可以获得最好信息. 学会解释EXPLAIN,你就会了解MySQL优化器是如何工作,你才 ...

  9. 详解MySQL中EXPLAIN解释命令(转)

    explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上explain就可以了: 如: expla ...

  10. mysql中explain的type的解释

    type -- 连接类型 type意味着类型,这里的type官方全称是“join type”,意思是“连接类型”,这样很容易给人一种错觉觉得必须需要俩个表以上才有连接类型.事实上这里的连接类型并非字面 ...

随机推荐

  1. 网络构建入门技术(3)——IP地址分类

    说明(2017-5-16 09:48:08): 1. IP地址

  2. [转]MySQL函数大全 及用法示例

    原文地址:http://blog.sina.com.cn/s/blog_4586764e0100h5ct.html 1.字符串函数ascii(str)   返回字符串str的第一个字符的ascii值( ...

  3. web前端开发与iOS终端开发的异同[转]

    * {-webkit-tap-highlight-color: rgba(0,0,0,0);}html {-webkit-text-size-adjust: none;}body {font-fami ...

  4. 改改"坏"代码

    程序猿很多时候费了九牛二虎之力使用各种黑科技实现了某个功能,终于可以交差,但整个过程就像个噩梦,一般人是不太愿意回过头去阅读自己写的代码的,交出去的代码就让它如往事般随风吧. 可你不愿读自己的代码,却 ...

  5. Maven Tomcat:run 使用tomcat7

    <build> <finalName>service</finalName> <resources> <resource> <dire ...

  6. python 基础笔记

    1,去掉了C语言中的大括号,用空格来对齐语句块.(空格一般用2个或4个,但没有限制) 2,要在py文件代码中使用中文,需要在第一行加入下面的代码: # -*- coding: utf-8 -*- 或者 ...

  7. mysql查找有某列但没有此列索引的表

    select a.TABLE_SCHEMA,a.TABLE_NAME from information_schema.`COLUMNS` a left join (select 'etl_stamp' ...

  8. 使用JAAS登录kerberos服务器

    java代码: package com.snsprj.jaas0822; import javax.security.auth.*; import javax.security.auth.callba ...

  9. 助你简化开发的 jQuery 插件

    Vanity Toolset vanity toolset是一套方便的UI工具集,可以帮助你快速的搭建幻灯,聚光灯,占位,收放相关的UI,它完成了大部分的UI功能,你只需要花费很少时间就可以构建一个完 ...

  10. Qt判断操作系统代码

    Qt4的时候是如下宏定义.Qt5,有所不同.   #include <QtGlobal> ... #ifdef Q_OS_MAC // mac #endif #ifdef Q_OS_LIN ...