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.

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


更多文章
  • 系统调用的过程
  • MySQL charset不同导致无法使用索引的坑
  • 微服务的缺点
  • 远程工作一周有感
  • Python中的并发控制
  • KVM spice协议在高分屏上的分辨率问题
  • 计算机中的权衡(trade-off)
  • [声明]本站所有文章禁止转载
  • Golang不那么蛋疼的sort
  • Flutter给Android应用签名
  • 使用Gitea+Drone打造自己的CI/CD系统
  • 2019年就要结束啦!
  • 为什么要使用gRPC?
  • Matebook X Pro 2019安装Debian 10
  • ArchLinux忽略某个包的升级