Using Filesort 和 Using Temporary:说明没有使用到索引。 impossible where:说明条件永远不成立。 use index:表示相应的select中使用了覆盖索引,避免访问了表的数据行, 效率很好 using where:表明使用了where过滤。 using join buffer:使用了连接缓存。 3. 分析常见问题和优化建议 在分析EXPLAIN输出时,可以根...
上面那个例子中其实就用到了:Using index,因为只返回一列code,它字段走了索引。 Using temporary表示是否使用了临时表,一般多见于order by 和 group by语句。执行sql如下: explain select name from test1 group by name; 结果: 图片 Using where表示使用了where条件过滤。 Using join buffer 表示是否使用连接缓冲。
SELECT* FROM(SELECTtarget, Count(*) FROMoperation GROUPBYtarget)t WHEREtarget='rm-xxxx'+---+---+---+---+---+---+---+---+---+---+ |id|select_type|table|type|possible_keys|key|key_len|ref|rows|Extra| +---+---+---+---+---+---+---+---...
|1|SIMPLE| m | ref | | idx_message_info |122| const |1|Usingindex condition | |1|SIMPLE| n | eq_ref | |PRIMARY|122| ighbor_id |1|Usingwhere | |1|SIMPLE| sra | ref | | idx_user_id |123| const |1|Usingwhere | +---+---+---+---+ ---+---+---+ ---+---+ ...
1.Using filesort 主要出现在 order by 排序、复合索引跨列; order by 排序 出现原因:查询a表,却根据b表排序,例如: 代码语言:javascript 复制 select*From test01 where a='3'order by b; 如果避免此情况出现,就根据什么字段查,就根据什么字段进行排序。如: ...
| 1 | PRIMARY | o | index | | PRIMARY | 8 | | 24 | Using where; Using temporary | | 2 | DEPENDENT SUBQUERY | | | | | | | | Impossible WHERE noticed after reading const tables | | 3 | DERIVED | o | ref | idx_2,idx_5 | idx_5 | 8 | const | 1 | Using where; Usi...
Using where;Using temporary||2|DEPENDENTSUBQUERY|||ImpossibleWHEREnoticed after readingconsttables||3|DERIVED|o|ref|idx_2,idx_5|idx_5|8|const|1|Using where;Using filesort|+---+---+---+---+---+---+---+---+---+---+ 重写为JOIN之后,子查询的选择模式从DEPENDENT SUBQUERY变成DERIVED...
| 1 | PRIMARY | o | index | | PRIMARY | 8 | | 24 | Using where; Using temporary | | 2 | DEPENDENT SUBQUERY | | | | | | | | Impossible WHERE noticed after reading const tables | | 3 | DERIVED | o | ref | idx_2,idx_5 | idx_5 | 8 | const | 1 | Using where; Usi...
Using temporary: 表示是否使用了临时表,性能特别差,需要重点优化。一般多见于group by语句,或者union语句。 Using where : 表示使用了where条件过滤. Using index condition:MySQL5.6之后新增的索引下推。在存储引擎层进行数据过滤,而不是在服务层过滤,利用索引现有的数据减少回表的数据。
你可以通过比较发现第一条语句会比第二句在Extra:里面多了Using filesort.而恰恰filesort是最耗时的。 优化ORDER BY语句 在某些情况中,MySQL可以使用一个索引来满足ORDER BY子句,而不需要额外的排序。WHERE 条件和 ORDER BY使用相同的索引,并且ORDER BY的顺序和索引顺序相同,并且ORDER BY的字段都是升序或者都是降序...