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.

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


更多文章
  • Golang validator使用教程
  • 使用Redis的Stream模块实现群聊功能
  • 价值编程与职业发展
  • 解决k8s cron无法读取环境变量的问题
  • 应用内购的坑
  • 两种常见的访问控制模型
  • gunicorn max-requests 选项的作用
  • Redis使用中的几点注意事项
  • 给你的代码跑个分?pylint使用教程
  • 一个Gunicorn worker数量引发的血案
  • MySQL Boolean类型的坑
  • pip freeze是魔鬼
  • 一个feed流系统的演进
  • Android 使用view binding
  • 系统调用的过程