zoukankan      html  css  js  c++  java
  • Mysql执行计划-extra

    一、extra

      

    二、extra实例

    1、Using temporary 使用了临时表

    EXPLAIN select * from myshop.ecs_users where user_id in (
    select user_id from myshop.ecs_users where user_id =1 union select user_id from myshop.ecs_users where user_id =2);

      输出

       最后一行,生成一个临时表

        

      从上图可以看到,最外层是全表扫描

    2、Using index condition 用了索引做判断

    EXPLAIN select * from myshop.ecs_users where email is null;

      输出

      type 显示 ref 用到了索引

    3、Using filesort 将用外部排序而不是按照索引顺序排列结果【差,需要加索引】

    EXPLAIN select * from myshop.ecs_order_info order by pay_fee;

      -- 正例 EXPLAIN select * from myshop.ecs_order_info order by order_id;

      type 为 ALL,Extra 为 Using flesort, 无法用到索引排序

      如果用到主键 id 排序,如下

    EXPLAIN select * from myshop.ecs_order_info order by order_id

      输出

       可以看到用到了索引。

    4、Using index 表示MySQL使用覆盖索引避免全表扫描

    EXPLAIN select * from myshop.ecs_users where user_id = (
    select max(LAST_INSERT_ID()) as user_id from myshop.ecs_users);

      输出

       用到了索引

    5、Using where 通常是进行了全表/全索引扫描后再用WHERE子句完成结果过滤【差,需要加索引或者sql写的不好】

    EXPLAIN select * from myshop.ecs_order_info where order_status < 1;

      输出

         

    6、Impossible WHERE 不成立的where判断。比如order_status字段不能为空

    EXPLAIN select * from myshop.ecs_order_info where order_status is null;

      输出

    7、Select tables optimized away 通过聚合函数来访问某个索引字段时,优化器一次定位到所需要的数据行完成整个查询【比较好】

    EXPLAIN select * from myshop.ecs_users where user_id = (
    select max(user_id) from myshop.ecs_users where email is null );

      输出

  • 相关阅读:
    Xcopy参数介绍
    C# 子窗体中调用父窗体中的方法(或多窗体之间方法调用)
    WinForm窗体之间交互的一些方法(转)
    C#.Net组件开发 使用Attach to Process实时调试设计器代码(转)
    win7以管理员身份运行程序
    如何关闭Windows7的UAC
    用“回车”键代替“Tab”键
    笑话20110928
    项目管理师
    软考计算机技术与软件专业技术资格(水平)考试
  • 原文地址:https://www.cnblogs.com/Jomini/p/14102227.html
Copyright © 2011-2022 走看看