sql - 摆脱 "Using temporary; Using filesort"

标签 sql mysql query-optimization

当我对查询进行解释时

enter image description here

我看到它在第一行的“额外”下有“使用临时;使用文件排序”。我知道这很糟糕,但我不知道这到底意味着什么或如何解决它。

如果您想查看我的查询,这里是我针对同一查询提出的更一般的问题:MySQL query optimization and EXPLAIN for a noob . 作为引用,查询涉及 24 个表和 23 个连接。

我现在的问题是:

  • “使用临时文件”和“使用文件排序”是什么意思?
  • 假设它们不好,我该如何摆脱它们?

最佳答案

如前所述,“使用文件排序”和“使用临时文件”并不总是意味着性能不佳。

Here是提高 ORDER BY 语句性能的一些基本准则。亮点:

If you want to increase ORDER BY speed, check whether you can get MySQL to use indexes rather than an extra sorting phase. If this is not possible, you can try the following strategies:

Increase the size of the sort_buffer_size variable.

Increase the size of the read_rnd_buffer_size variable.

Use less RAM per row by declaring columns only as large as they need to be to hold the values stored in them. For example, CHAR(16) is better than CHAR(200) if values never exceed 16 characters.

首先尝试使用索引(确保您排序的字段有索引)。注意增加系统变量sort_buffer_sizeread_rnd_buffer_size也可能对其他查询产生负面影响 - 考虑专门为您需要它们的 session 设置它们,并将它们保留为所有其他 session 的默认值。

关于sql - 摆脱 "Using temporary; Using filesort",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4935391/

相关文章:

sql - 如何为多语言列创建全文索引?

sql - 如何使用嵌入式 SQL 迭代 RPG(LE) 中的一组记录?

c# - Need Insight - 需要 webservice c# .net TO php mysql 的软件开发人员

MySQL-优化查询

sql - 从此 sql server 文章翻页的有效方法

mysql - SQL 和外键,引用

mysql - 我可以在 MySQL 中执行可选的 LEFT JOIN 吗?

php - 如何使用 ajax jquery、php 和 mysql 进行 auto_search

MySQL性能: join of two tables on common foreign key: still "using where"

postgresql - PostgreSQL 用于查询处理和优化的中间语言是什么?