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  --执行计划参考

最新文章

  1. react学习小结(生命周期- 实例化时期 - 存在期- 销毁时期)
  2. css3 风车旋转
  3. iOS 钥匙串 指纹识别 get和Post请求的区别
  4. flex容器属性(一)
  5. Java读取Execl表格数据
  6. UINavigation Bar中使用UIcollectionView,在UIcollectionView的顶端和低端出现空白的问题
  7. 编程范式 epesode7,8 stack存放指针类型and heap,register
  8. 跟我学STL系列(1)——STL入门介绍
  9. JS中检测数据类型的几种方式及优缺点
  10. 【转】JavaSript模块规范 - AMD规范与CMD规范介绍
  11. C/C++变量命名规则
  12. win7 下面使用任务计划程序执行php脚步
  13. ZOJ Problem Set - 3829Known Notation(贪心)
  14. 程序设计 之 C#实现《拼图游戏》
  15. UML之概述
  16. asp.net mvc 通过StyleBundle添加样式后,没有作用
  17. WPF Dispatcher介绍
  18. Apache服务器下phalcon项目报Mod-Rewrite is not enabled问题
  19. HTTPS的安全性
  20. Elasticsearch 学习之 Marvel概念

热门文章

  1. C#学习笔记(13)——传统方法读取XML
  2. Server.MapPath 出现未将对象引用设置到对象的实例
  3. python 6种数据类型几及用法
  4. composer安装与应用
  5. 15.01.29-MVC中用Areas分解项目
  6. excel数据批量导入
  7. 自定义垂直拖动的seekbar进度条
  8. 初探Asp.net请求机制原理 1
  9. Android Custom View系列《圆形菜单一》
  10. tortoiseSVN 合并代码方法