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. python 基础总结1

    1.python简介特点:    是简单义学,有功能强大,高性能.面向对象,对动态输入的支持.解释性语言的本质,是大多数平台上理想的脚本语言. 简单,义学                    免费, ...

  2. u-boot2016.05 有关 4096page size , oob == 224 nand 的移植支持

    大致介绍一下这个 nand 的基础属性 pagesize == 4096 byte oob == 224 byte block size == 256 Kbyte u-boot configs/xxx ...

  3. u-boot的配置

    1 sama5d31dk           sama5d3_xplained:SAMA5D3,SYS_USE_NANDFLASH                                    ...

  4. Go Revel - Filter(过滤器)源码分析

    在 Go Revel - server.go 源码分析 http://www.cnblogs.com/hangxin1940/p/3265538.html 说到revel框架很多重要的东西都Filte ...

  5. c++------------提取文件中的信息

    对于文件比较复杂的时候,为了获取文件中的信息,需要一些比较特殊的函数,比如,getline().replace().atoi,atof等 例子一,读取以下文件中的数据,并保存进一个类里面. 首先,类的 ...

  6. 【linux】——一个小程序

    利用工作之余为小伙伴写了份作业,关于进程间通信的.题目如下: 父进程从键盘上接受1000个数据,对其求和sum1,子进程对这1000个数平方和sum2,结果传给父进程,父进程将sum1+sum2后,打 ...

  7. Android Studio xcode单步调试 WebRTC Android & iOS

    mac环境 如何在 Android Studio 里单步调试 WebRTC Android 的 native 代码. WebRTC 代码下载 depot tools 是 chromium 代码库管理工 ...

  8. java生成word的完美解决方案

    http://www.360doc.com/content/13/0731/10/13247663_303740756.shtml —————————————————————————————————— ...

  9. Jquery ThickBox的使用

    thickbox是jQuery的一个插件,其作用是弹出对话框.网页框,使用户体验度更加愉悦,下面就来简单介绍它的几种用法.声明一下:这只是个人的总结记载而已.准备工作:你需要三个文件:thickbox ...

  10. Golang (Go语言) Mac OS X下环境搭建 环境变量配置 开发工具配置 Sublime Text 2 【转】

    一.安装Golang的SDK 在官网 http://golang.org/ 直接下载安装包安装即可.下载pkg格式的最新安装包,直接双击运行,一路按照提示操作即可完成安装. 安装完成后,打开终端,输入 ...