Home > Database > Mysql Tutorial > MySQL5.6优化了派生子查询

MySQL5.6优化了派生子查询

WBOY
Release: 2016-06-07 17:36:49
Original
1046 people have browsed it

网友黄华亮发了一条SQL的执行计划问t表的字段TOP_TITLE_ID是主键,为啥orderby还会有Usingtemporary;Usingfilesort后来我把该表要了过来,在我的机器上做了下测

网友黄华亮发了一条SQL的执行计划

wKioL1L50MWDH3pUAAR7wzsTzM0173.jpg

问t表的字段TOP_TITLE_ID是主键,为啥order by还会有Using temporary; Using filesort


后来我把该表要了过来,在我的机器上做了下测试,如果改成如下SQL就没有Using temporary; Using filesort

wKiom1L50h-iYgV1AAN1s01J8DI458.jpg


于是又在5.6上测试了一下,,发现:

wKiom1L50oThf_doAAUcH1PMmyc418.jpg

同样的SQL语句,在MySQL5.6上就去掉了Using temporary; Using filesort


仔细查看了手册,

wKiom1L504PysREXAAD0IMIxVzs550.jpg

wKioL1L501_jtwOZAAFHPAggZSQ654.jpg

就是说采用一个索引将子查询的结果存进一个临时表,并且利用这个临时表来执行一个连接。这里c表TOP_TITLE_ID字段是索引,关联t表的字段TOP_TITLE_ID是主键,Using temporary; Using filesort也就消失了。



本文出自 “贺春旸的技术专栏” 博客,请务必保留此出处

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template