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 );
输出