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.

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


更多文章
  • Linux下当笔记本合上盖子之后只使用扩展显示器
  • Ubuntu 18.04 dhcp更换新IP
  • Python中的新式类(new style class)和老式类(old style class)
  • Python Requests 简明教程
  • 密码技术简明教程(三):证书和TLS
  • SEO学习笔记
  • 密码技术简明教程(二):散列、消息认证码和数字签名
  • 密码技术简明教程(一):对称加密和非对称加密
  • Kubernetes 笔记
  • go mod 和 logrus 路径大小写的问题
  • Flask自动加载Blueprint
  • 在KVM里安装Minikube
  • 搞定面试中的系统设计题
  • Crontab + Sendmail实现定时任务并且通知
  • Nginx设置Referer来防止盗图