从上面的解释上来看,filesort和temporary的使用场景的区别并不是很明显,不过,有以下的原则: filesort只能应用在单个表上,如果有多个表的数据需要排序,那么MySQL会先使用using temporary保存临时数据,然后再在临时表上使用filesort进行排序,最后输出结果。 参考:数据库内核月报 1.What does Using filesort mean in MySQL?
explain select s.* from tb_wm_popularize p left join tb_wm_shop s on p.shop_id = s.id where s.is_delete != 1 AND p.type = 1 order by s.sale_num desc 这条语句就比较讨人厌了,同时出现了Using temporary(临时表)、Using filesort(文件排序) 一个小时的百度,找到了原因 其一,参考:http...
其次将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已经创建了索引,但是...
explainselectf.id,f.oid,f.first_course_timefromo_order_financefinnerjoino_orderoonf.oid=o.idwheref.id>0andf.first_course_time=0ando.status=3orderbyf.idlimit100; 使用了Using temporary Using filesort,这个涉及到这两个的含义: Using temporary 表示由于排序没有走索引、使用union、子查询连接查询、...
explain的使用很简单,就是在select 语句之前增加explain关键字就ok了。MySQL 会在查询上设置一个标记,执行查询时,会返回执行计划的信息,而不是执行这条SQL。比如这样: # explain + sqlexplainselect*fromtablewherea=1; Explain执行计划能做什么? 确定表的读取顺序 ...
一次mysql 优化 (Using temporary ; Using filesort) 遇到一个SQL执行很慢 SQL 如下: SELECT ... FROM tableA WHERE time >= 1492044535 and time <= 1492046335 GROUP by time, sourceName, serverSite,clientSite; 1. 2. 3. 4. 5. SELECT 部分忽略没写,是因为通常SQL执行慢不会跟这部分有关系,至少...
If I remove the GROUP BY then the EXPLAIN says Using where; Using index with no temporary or file sort and the query runs in 2 seconds instead of 6 seconds. Having these results grouped by the Test ID is mandatory. Also the Test ID values are arbitrary and not known in advance, so ...
Using filesort:MySQL需要额外的一次传递,以找出如何按排序顺序检索行,说明查询就需要优化了。 Using index:从只使用索引树中的信息而不需要进一步搜索读取实际的行来检索表中的列信息。 Using temporary:为了解决查询,MySQL需要创建一个临时表来容纳结果,说明查询就需要优化了。
MySQL · 答疑释惑· using filesort VS using temporary 文章中: create table t1( id int, col1 int, col2 varchar(10), key(id, col1)); create table t2( id int, col1 int, col2 varchar(10), key(col1)); case2: mysql> explain select * from t1 force index(id), t2 where t1.id...