MySQL EXPLAIN中的filesort是什么?

最开始我一为filesort是外排。结果不是,EXPLAIN中这个提示非常具有误导性。只要排序的时候不能用上索引,就会显示成filesort。 MySQL所谓的”filesort”进行的动作:

  • Read the rows that match the WHERE clause
  • For each row, store in the sort buffer a tuple consisting of the sort key value and the columns referenced by the query
  • When the sort buffer becomes full, sort the tuples by sort key value in memory and write it to a temporary file
  • After merge-sorting the temporary file, retrieve the rows in sorted order, but read the columns required by the query directly from the sorted tuples rather than by accessing the table a second time.

注意,当内存放不下所有的数据时,数据会被分块,对于每个块应用快排,对于多个块应用合并排序。


更多文章
  • 折腾Kubernetes
  • 协程(coroutine)简介 - 什么是协程?
  • goroutine 切换的时候发生了什么?
  • Prometheus 数据类型
  • Gin源码阅读与分析
  • 如何面试-作为面试官得到的经验
  • 自己写一个容器
  • Golang(Go语言)中实现典型的fork调用
  • 软件开发之禅---大事化小,各个击破
  • 程序员的自我修养:链接,装载与库 阅读笔记
  • Redis源码阅读与分析三:哈希表
  • Redis源码阅读与分析一:sds
  • Redis源码阅读与分析二:双链表
  • Golang runtime 源码阅读与分析
  • Golang的一些坑