mysql+filesort+index_MySQL优化-filesort-Using index condition

首先要明白SQL的运行流程,方便理解。

http://blog.itpub.net/22664653/viewspace-1210844/

https://tech.meituan.com/mysql-index.html

阿里大神:

https://yq.aliyun.com/topic/100?spm=5176.8217306.rtdmain.3.vmqTwp

ICP 关闭时 ,仅仅使用索引作为访问数据的方式。

2e75c61337d57b5c69df92633aa67d6f.png

ICP 开启时 ,MySQL将在存储引擎层 利用索引过滤数据,减少不必要的回表,注意 虚线的using where 表示如果where条件中含有没有被索引的字段,则还是要经过MySQL Server 层过滤。

8d44c4d1f878362100db9de8df93f4b8.png

#################

sending data   存储引擎搜集数据发送到客户端。

################

filesort

https://dev.mysql.com/doc/refman/5.7/en/order-by-optimization.html

#################

num1 是辅助索引

num2 是唯一索引

id是主键

desc select id,num1 from a where num1=2 order by id;  ######考点是二级索引的叶子节点包含主键,不需要回表,(num1,id)是逻辑有序的,不会出现filesort。using index

desc select * from a where num1=2 order by id;        #######考点是select * ,会回表,(num1,id)是逻辑有序的,不会出现filesort。using index condition

desc select * from a where num1 > 2 order by id;     #######考点是num1>2,由于是范围查询,后面的(num1,id),id是逻辑无序的,会出现filesort

desc select num1 from a where num1=2 order by num2;  ######考点是order by num2,  通过num1=2,num2非逻辑有序。会出现filesort

desc select * from a  order by num1;    #####考点不加where的条件,order by 会导致filesort。因为出现全表扫描,没有走索引。

desc select * from a join b on a.id=b.id  where a.num1=2 order by b.num1;  ########考点where后面先查询的a.num1,order by的b表。逻辑上无序,所以a表Using temporary; Using filesor

desc select * from a order by num1 ,num2;  ###全表扫描会出现filesort,复合索引也还是有filesort

desc select * from a where num1=2 order by num1 ,num2;####有复合索引,会使用Using index condition

select * 还是select id 决定了是using index condition还是using index。

一句话的总结:filesort主要是看where后列的条件是否逻辑有序。

杨奇龙总结:

http://blog.itpub.net/22664653/viewspace-2143086/

#################

驱动表的理解:

https://yq.aliyun.com/articles/9048?spm=5176.153233.793261.6.qMiZ2q

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值