这是因为mysql底层 优化器发现因为有status这个条件,而这个条件在o_order表有索引,所以使用u_order表的id排序能走索引,这就解释通了,为啥只是换了order by 字段 便能够从20秒优化到了0.4秒。 参考文献:Mysql 调优记: INNER JOIN查询 Using temporary; Using filesort 问题优化...
| 1 | SIMPLE | acl | ALL | FKE43AF088F9936F96 | NULL | NULL | NULL | 94 | Using where; Using temporary; Using filesort | | 1 | SIMPLE | permission | eq_ref | PRIMARY | PRIMARY | 98 | bs_common.acl.PERMISSION_ID | 1 | Using where | +---+---+---+---+---+---...
-- 首先,创建一个覆盖索引来加速查询 CREATE INDEX idx_biz_work_order_label_optimized ON biz_work_order_label (deleted, label_type, work_order_id) WHERE deleted = 0; CREATE INDEX idx_biz_work_order_optimized ON biz_work_order (deleted, problem_location_code, reporting_time, nature, id) WH...
LEFTJOINrank_user_login_statASuserLoginInfoONrankUser.id = userLoginInfo.user_id ORDERBY rankUser.create_timeDESC LIMIT 10 OFFSET 0
如果order by的子句只引用了联接中的第一个表,MySQL会先对第一个表进行排序,然后进行联接。也就是expain中的Extra的Using Filesort.否则MySQL先把结果保存到临时表(Temporary Table),然后再对临时表的数据进行排序.此时expain中的Extra的显示Using temporary Using Filesort. ...
case2: order by谓词,是在第一个表t1上完成,所以只需要在t1表上使用filesort,然后排序后的结果集join t2表。 case 3: order by的字段在t2表上,所以需要把t1,t2表join的结果保存到temporary表上,然后对临时表进行filesort,最后输出结果。 我的问题: ...
其次将extra⼀栏的Using temporary(临时表)、Using filesort(⽂件排序)拖出去砍了 ⼀、第⼀条语句 explain select*from tb_wm_shop where is_delete !=1and is_authentication =1ORDER BY create_time DESC ⼤家应该知道使⽤order by的字段要使⽤索引,这条语句中create_time已经创建了索引,但是...
ORDER BY rankUser.create_time DESC LIMIT 10 OFFSET 0 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 介绍一下这段sql的表的构成:一张主表:rank_user;两张跟rank_user直接关联(多张表通过同一字段最好是主键进行关联)的表:rank_user_level ,rank_user_login_stat ;两张跟rank_user非直接关联的表:...
It is sometimes impossible to get rid of "using temporary" and "file sort". Problem 1: The WHERE clause spans two tables. Problem 2: There is an ORDER BY. This often (but not always) requires gather all the data, then sorting it -- hence the temporary and filesort. Non-Problem...
Using temporary,表示需要创建临时表以满足需求,通常是因为GROUP BY的列没有索引,或者GROUP BY和ORDER BY的列不一样,也需要创建临时表,建议添加适当的索引。 Using filesort,表示无法利用索引完成排序,也有可能是因为多表连接时,排序字段不是驱动表中的字段,因此也没办法利用索引完成排序,建议添加适当的索引。