Using index, using temporary, using filesort - how to fix this?
解释一:
These are the following conditions under which temporary tables are created. UNION queries use temporary tables.
Some views require temporary tables, such those evaluated using the TEMPTABLE algorithm, or that use UNION or aggregation.
If there is an ORDER BY clause and a different GROUP BY clause, or if the ORDER BY or GROUP BY contains columns from tables other than the first table in the join queue, a temporary table is created.
DISTINCT combined with ORDER BY may require a temporary table.
If you use the SQL_SMALL_RESULT option, MySQL uses an in-memory temporary table, unless the query also contains elements (described later) that require on-disk storage.
Follow this link by mysql: http://dev.mysql.com/doc/refman/5.1/en/internal-temporary-tables.html
译文:
以下是创建临时表的条件。 UNION查询使用临时表。
某些视图需要使用TEMPTABLE算法评估的临时表,或使用UNION或聚合的临时表。
如果存在ORDER BY子句和不同的GROUP BY子句,或者如果ORDER BY或GROUP BY包含来自联接队列中第一个表以外的表的列,则会创建一个临时表。
与ORDER BY组合的DISTINCT可能需要临时表。
如果使用SQL_SMALL_RESULT选项,MySQL将使用内存中的临时表,除非该查询还包含需要磁盘存储的元素(稍后介绍)。
按照mysql的这个链接:http://dev.mysql.com/doc/refman/5.1/en/internal-temporary-tables.html
解释二:
Updated for MySQL 5.7 (src):
The server creates temporary tables under conditions such as these:
Evaluation of UNION statements, with some exceptions described later.
Evaluation of some views, such those that use the TEMPTABLE algorithm, UNION, or aggregation.
Evaluation of derived tables (subqueries in the FROM clause).
Tables created for subquery or semi-join materialization (see Section 8.2.2, “Optimizing Subqueries, Derived Tables, and View References”).
Evaluation of statements that contain an ORDER BY clause and a different GROUP BY clause, or for which the ORDER BY or GROUP BY contains columns from tables other than the first table in the join queue.
Evaluation of DISTINCT combined with ORDER BY may require a temporary table.
For queries that use the SQL_SMALL_RESULT modifier, MySQL uses an in-memory temporary table, unless the query also contains elements (described later) that require on-disk storage.
To evaluate INSERT ... SELECT statements that select from and insert into the same table, MySQL creates an internal temporary table to hold the rows from the SELECT, then inserts those rows into the target table. See Section 13.2.5.1, “INSERT ... SELECT Syntax”.
Evaluation of multiple-table UPDATE statements.
Evaluation of GROUP_CONCAT() or COUNT(DISTINCT) expressions.
译文:
更新MySQL 5.7(src):
服务器在如下条件下创建临时表:
UNION报表的评估,稍后会有一些例外情况。
评估一些视图,例如使用TEMPTABLE算法,UNION或聚合的视图。
派生表的评估(FROM子句中的子查询)。
为子查询或半连接实现创建的表(请参见第8.2.2节“优化子查询,派生表和视图引用”)。
评估包含ORDER BY子句和不同GROUP BY子句的语句,或者ORDER BY或GROUP BY包含来自联接队列中第一个表以外的表的列的语句。
DISTINCT与ORDER BY结合使用可能需要一个临时表。
对于使用SQL_SMALL_RESULT修饰符的查询,MySQL使用内存中的临时表,除非查询还包含需要磁盘存储的元素(稍后介绍)。
为了评估从同一个表中选择并插入到同一个表中的INSERT ... SELECT语句,MySQL创建一个内部临时表来存放SELECT中的行,然后将这些行插入到目标表中。请参见第13.2.5.1节“INSERT ... SELECT语法”。
评估多表UPDATE语句。
评估GROUP_CONCAT()或COUNT(DISTINCT)表达式。
原文地址:https://stackoverflow.com/questions/13633406/using-index-using-temporary-using-filesort-how-to-fix-this
Using index, using temporary, using filesort - how to fix this?的更多相关文章
- Mysql EXPLAIN 相关疑问: Using temporary ; Using filesort
一.什么是Using temporary ; Using filesort 1. using filesort filesort主要用于查询数据结果集的排序操作,首先MySQL会使用sort_buff ...
- EXPLAIN sql优化方法(2) Using temporary ; Using filesort
优化GROUP BY语句 默认情况下,MySQL对所有GROUP BY col1,col2...的字段进行排序.这与在查询中指定ORDER BY col1,col2...类似.因此,如果显式包括一 ...
- 一次mysql 优化 (Using temporary ; Using filesort)
遇到一个SQL执行很慢 SQL 如下: SELECT ... FROM tableA WHERE time >= 1492044535 and time <= 1492046335 GRO ...
- mysql查询优化--临时表和文件排序(Using temporary; Using filesort问题解决)
先看一段sql: <span style="font-size:18px;">SELECT * FROM rank_user AS rankUser LEFT JOIN ...
- HOW MYSQL USES INTERNAL TEMPORARY TABLES
HOW MYSQL USES INTERNAL TEMPORARY TABLES Table of Contents [hide] 1)UNION queries 2)Some views 3)SQL ...
- Mysql中的force index和ignore index
前几天统计一个sql,是一个人提交了多少工单,顺便做了相关sql优化.数据大概2000多w. ) c order by c desc; 为了实验最少受其他因素干扰,将生产库的200多w数据导出来,用测 ...
- Mysql force index和ignore index 使用实例
前几天统计一个sql,是一个人提交了多少工单,顺便做了相关sql优化.数据大概2000多w. select CustName,count(1) c from WorkOrder where Creat ...
- [慢查优化]联表查询注意谁是驱动表 & 你搞不清楚谁join谁更好时请放手让mysql自行判定
写在前面的话: 不要求每个人一定理解 联表查询(join/left join/inner join等)时的mysql运算过程: 不要求每个人一定知道线上(现在或未来)哪张表数据量大,哪张表数据量小: ...
- mysql使用索引扫描来做排序
mysql有两种方式可以生成有序的结果,通过排序操作或者按照索引顺序扫描,如果explain的type列的值为index,则说明mysql使用了索引扫描来做排序(不要和extra列的Using ind ...
随机推荐
- android制作闪动的红心
先上一张效果图吧: 说说这个东西的来源吧.今天突然想到笛卡尔心形图,想去看看能不能画个心出来,可是看到一篇不错的文章,那篇文章罗列了非常多关于心形的函数方程,这可把我高兴坏了,于是我选取了一个比較好看 ...
- Unity 使用C/C++ 跨平台终极解决方式(PC,iOS,Android,以及支持C/C++的平台)
PC的事实上根本不用说,毕竟C#和C++交互的文章已经够多了,当然我自觉得经过几次折腾后.差点儿全部游戏须要到的操作我都掌握了(各种传參方法,各种坑,不懂的能够留言问.尽管基本上没人看.哈哈) 废话不 ...
- HTML的表单form以及form内部标签
<html> <head> <title> form表单的使用 </title> <!-- 标签名称:form 表单标签 属性:action:提交 ...
- Jetty:部署到Jetty
Web应用的框架 标准Jetty公布版本号能部署标准servlet Spec Web应用和Jetty内部ContextHandler部署描写叙述符,或者两者的一个混合. Web应用是可部署的动态(se ...
- 编程基础知识——C++能不能支持Java和ObjC的反射?
C++能不能支持Java和ObjC的反射? 要回答这个问题.首先我们要清楚什么是反射.什么是反射? 教科书的解释我就不说了,(^o^)事实上我也记不得.实际开发应用的反射就是在没有某个类型的头文件或者 ...
- 2016.04.11,英语,《Vocabulary Builder》Unit 12
umbr, from the Latin umbra, 'shadow', umbrella, -ella, 'little', means 'little shadow'. adumbrate: [ ...
- js面试题--js的继承
js是门灵活的语言,实现一种功能往往有多种做法,ECMAScript没有明白的继承机制.而是通过模仿实现的.依据js语言的本身的特性,js实现继承有下面通用的几种方式 1.使用对象冒充实现继承(该种实 ...
- JavaScript或者Jqurey把控件id作为參数来调用
1.JavaScript把控件id作为參数调用 <script type="text/javascript"> function xx(pmba) { document ...
- POJ3090 Visible Lattice Points 欧拉筛
题目大意:给出范围为(0, 0)到(n, n)的整点,你站在原点处,问有多少个整点可见. 线y=x和坐标轴上的点都被(1,0)(0,1)(1,1)挡住了.除这三个钉子外,如果一个点(x,y)不互质,则 ...
- contest hunter5105 Cookies
神题 先按贪婪值大到小排序,根据贪心的思想g[i]越大a[i]也越大(这个微扰可以证,给个提示,a>b且c<d 则 (a-b)(c-d)<0 则 ac+bd<ad+bc) DP ...