我是个笨比 2021-09-19 21:18 采纳率: 100%
浏览 29
已结题

你好,问题太长标题放不下,请看内容区域。

问题1:您好,我想问一下我这样理解对不对!这个表中有三个字段id(primary key),name(index),deptId(foreign key),索引在B+树上的存储内容除了索引本身,应该还有主键,所以下面select id就不会产生filesort,但是当我们想把所有字段都查出来的时,select 的执行顺序在order by之前,根据name排序但是没有deptId这个字段的信息,所以必须在select查出来的记录中再排序一次。

img

  • 写回答

2条回答 默认 最新

  • ACMAIN_CHM 2021-09-20 16:31
    关注

    理解正确。
    https://dev.mysql.com/doc/refman/5.7/en/explain-output.html#explain-extra-information

    Using filesort (JSON property: using_filesort)

    MySQL must do an extra pass to find out how to retrieve the rows in sorted order. The sort is done by going through all rows according to the join type and storing the sort key and pointer to the row for all rows that match the WHERE clause. The keys then are sorted and the rows are retrieved in sorted order. See Section 8.2.1.14, “ORDER BY Optimization”.

    Using index (JSON property: using_index)

    The column information is retrieved from the table using only information in the index tree without having to do an additional seek to read the actual row. This strategy can be used when the query uses only columns that are part of a single index.

    For InnoDB tables that have a user-defined clustered index, that index can be used even when Using index is absent from the Extra column. This is the case if type is index and key is PRIMARY.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月29日
  • 已采纳回答 9月21日
  • 创建了问题 9月19日

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等