Home Database Mysql Tutorial 理解Explain命令输出中的filesort

理解Explain命令输出中的filesort

Jun 07, 2016 pm 04:31 PM
explain Order understand output

前段时间看了 mysqlperformance blog 上一篇关于 filesort 的文章 ,看到 Percona 公司在招聘面试的时候常问应聘者“Explain 命令输出中的 filesort 的含义是什么”这个问题,而且基本上都得不到正确的答案,甚感奇怪。 按理这是非常基础的内容了,既然敢于

前段时间看了 mysqlperformance blog 上一篇关于 filesort 的文章 ,看到 Percona 公司在招聘面试的时候常问应聘者“Explain 命令输出中的 filesort 的含义是什么”这个问题,而且基本上都得不到正确的答案,甚感奇怪。

按理这是非常基础的内容了,既然敢于去 Percona 这样高手如云的公司应聘,不应该不清楚这个问题吧。

所以我也试探性的问了 MySQL圈子 中的几位朋友这个问题,结果和 Percona 所遇到的情况基本一样,仅有 1/10 的朋友真正明白 filesort 的含义,而且给出的错误答案也都和 Percona应聘者的答案差不多:是 mysql 在进行排序的时候,临时表太大,超出 MySQL 限制,需要将数据写出到磁盘文件中进行排序,所以称之为filesort。

这个“貌似正确”的答案,大部分都是因为 “filesort” 这个词的字面含义所误导猜测出来的。看来并不仅仅只有中国人喜欢“望文生义”,老外也是一样嘛!

那 Explain 命令输出信息中的 filesort 到底是什么意思呢?其实很简单,就是告诉你 MySQL 需要进行实际的排序操作而不能通过索引获得已排序数据。

个人觉得上面的错误答案其实至少错了以下两点:

  • filesort(其实就是排序) 可不一定会产生临时表哦
  • filesort 与临时表数据写入磁盘是没有任何直接联系的

上面两点错误中第一点在 MySQL Performance Blog 的文章中也提到了。

实际上,在我之前的一篇文章 MySQL ORDER BY 的实现分析 中已经很清楚的分析了 MySQL 在进行排序的时候,只有当返回的数据和排序条件不在同一个表中的时候,才需要使用到临时表。

学技术,真的是要非常严谨才行,如果我们仅仅通过字面意思来猜想其含义,而不仔细阅读文档并分析实验,很多时候得到的答案可能都是错误的。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run SUDO commands in Windows 11/10 How to run SUDO commands in Windows 11/10 Mar 09, 2024 am 09:50 AM

The sudo command allows users to run commands in elevated privilege mode without switching to superuser mode. This article will introduce how to simulate functions similar to sudo commands in Windows systems. What is the Shudao Command? Sudo (short for "superuser do") is a command-line tool that allows users of Unix-based operating systems such as Linux and MacOS to execute commands with elevated privileges typically held by administrators. Running SUDO commands in Windows 11/10 However, with the launch of the latest Windows 11 Insider preview version, Windows users can now experience this feature. This new feature enables users to

How to check the MAC address of the network card in Win11? How to use the command to obtain the MAC address of the network card in Win11 How to check the MAC address of the network card in Win11? How to use the command to obtain the MAC address of the network card in Win11 Feb 29, 2024 pm 04:34 PM

This article will introduce readers to how to use the command prompt (CommandPrompt) to find the physical address (MAC address) of the network adapter in Win11 system. A MAC address is a unique identifier for a network interface card (NIC), which plays an important role in network communications. Through the command prompt, users can easily obtain the MAC address information of all network adapters on the current computer, which is very helpful for network troubleshooting, configuring network settings and other tasks. Method 1: Use "Command Prompt" 1. Press the [Win+X] key combination, or [right-click] click the [Windows logo] on the taskbar, and in the menu item that opens, select [Run]; 2. Run the window , enter the [cmd] command, and then

Where is hyperv enhanced session mode? Tips for enabling or disabling Hyper-V enhanced session mode using commands in Win11 Where is hyperv enhanced session mode? Tips for enabling or disabling Hyper-V enhanced session mode using commands in Win11 Feb 29, 2024 pm 05:52 PM

In Win11 system, you can enable or disable Hyper-V enhanced session mode through commands. This article will introduce how to use commands to operate and help users better manage and control Hyper-V functions in the system. Hyper-V is a virtualization technology provided by Microsoft. It is built into Windows Server and Windows 10 and 11 (except Home Edition), allowing users to run virtual operating systems in Windows systems. Although virtual machines are isolated from the host operating system, they can still use the host's resources, such as sound cards and storage devices, through settings. One of the key settings is to enable Enhanced Session Mode. Enhanced session mode is Hyper

Super practical! Sar commands that will make you a Linux master Super practical! Sar commands that will make you a Linux master Mar 01, 2024 am 08:01 AM

1. Overview The sar command displays system usage reports through data collected from system activities. These reports are made up of different sections, each containing the type of data and when the data was collected. The default mode of the sar command displays the CPU usage at different time increments for various resources accessing the CPU (such as users, systems, I/O schedulers, etc.). Additionally, it displays the percentage of idle CPU for a given time period. The average value for each data point is listed at the bottom of the report. sar reports collected data every 10 minutes by default, but you can use various options to filter and adjust these reports. Similar to the uptime command, the sar command can also help you monitor the CPU load. Through sar, you can understand the occurrence of excessive load

What is the correct way to restart a service in Linux? What is the correct way to restart a service in Linux? Mar 15, 2024 am 09:09 AM

What is the correct way to restart a service in Linux? When using a Linux system, we often encounter situations where we need to restart a certain service, but sometimes we may encounter some problems when restarting the service, such as the service not actually stopping or starting. Therefore, it is very important to master the correct way to restart services. In Linux, you can usually use the systemctl command to manage system services. The systemctl command is part of the systemd system manager

How to use LSOF to monitor ports in real time How to use LSOF to monitor ports in real time Mar 20, 2024 pm 02:07 PM

LSOF (ListOpenFiles) is a command line tool mainly used to monitor system resources similar to Linux/Unix operating systems. Through the LSOF command, users can get detailed information about the active files in the system and the processes that are accessing these files. LSOF can help users identify the processes currently occupying file resources, thereby better managing system resources and troubleshooting possible problems. LSOF is powerful and flexible, and can help system administrators quickly locate file-related problems, such as file leaks, unclosed file descriptors, etc. Via LSOF Command The LSOF command line tool allows system administrators and developers to: Determine which processes are currently using a specific file or port, in the event of a port conflict

Detailed explanation of Linux ldconfig command Detailed explanation of Linux ldconfig command Mar 14, 2024 pm 12:18 PM

Detailed explanation of the Linuxldconfig command 1. Overview In the Linux system, ldconfig is a command used to configure shared libraries. It is used to update the links and cache of shared libraries and enable the system to load dynamically linked shared libraries correctly. The main function of ldconfig is to find dynamic link libraries and create symbolic links for program use. This article will delve into the usage and working principle of the ldconfig command, and use specific code examples to help readers better understand the functions of ldconfig

How to install and use exa on Linux system? How to install and use exa on Linux system? Mar 01, 2024 pm 06:31 PM

To install and use exa on a Linux system, you can follow these steps: Open Terminal: In Linux systems, press the Ctrl+Alt+T key combination to open the terminal. Download exa: exa is a modern ls replacement tool that provides a more beautiful and feature-rich file listing. Enter the following command in the terminal to download exa: wget This command will download the compressed file of exa from GitHub. Decompress exa: Use the following command to decompress the downloaded exa compressed file: unzipexa-linux-x86_64-0.10.1.zip After decompression, an executable file named exa will be generated. Install exa: Copy the exa file to the system's

See all articles