Home > Database > Mysql Tutorial > mysql的Late row lookups(延迟row查找)_MySQL

mysql的Late row lookups(延迟row查找)_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 13:36:25
Original
1223 people have browsed it

bitsCN.com

mysql的Late row lookups(延迟row查找)

 

Sql代码

CREATE TABLE `20130122handler` (  

  `id` int(11) NOT NULL AUTO_INCREMENT,  

  `uid` int(11) NOT NULL,  

  `content` varchar(50) NOT NULL,  

  PRIMARY KEY (`id`),  

  KEY `20130122handler_idx_uid` (`uid`)  

) ENGINE=InnoDB  

里面有60w数据,现在模拟按uid排序分页的情况 

要看第七页的内容,用 

Sql代码  

select SQL_NO_CACHE * from 20130122handler  

order by uid LIMIT 120,20  

 

查找20条数据,基本就是瞬间的事情 

假设用户比较变态,直接点到了102页,用 

Sql代码  

select SQL_NO_CACHE * from 20130122handler  

order by uid LIMIT 2020,20  

查找20条数据,发现各种性能相当差 

似乎mysql在这种情况下,要从20130122handler_idx_uid索引中读取2040条secondary记录, 

然后执行2040次的主键查询,然后返回20条,所以浪费了2020次主键查询 

可以考虑用这种手段,减少无用的row lookup 

Sql代码  

select SQL_NO_CACHE m.* from(  

 select uid from 20130122handler  

 ORDER BY uid LIMIT 2020,20) t,20130122handler m  

where t.uid=m.uid  

 

这是因为20130122handler_idx_uid是secondary索引,所以要row lookup 

用了 

Sql代码  

select SQL_NO_CACHE * from 20130122handler  

order by id LIMIT 120,20  

select SQL_NO_CACHE * from 20130122handler  

ORDER BY id LIMIT 2040,20  

 

差别就不明显了 

 

bitsCN.com
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