Heim >Datenbank >MySQL-Tutorial >mysql的Late row lookups(延迟row查找)_MySQL

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:36:251228Durchsuche

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
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn