Heim  >  Artikel  >  Datenbank  >  MySQL 优化Limit分页

MySQL 优化Limit分页

WBOY
WBOYOriginal
2016-06-07 16:38:46792Durchsuche

很多时候、我们需要选择出从指定位置开始的指定行数、此时、limit笑了 ? ? ?对于limit的定义是: ? ? ?limit x,y ? ? ?表示从第x行开始选择y条记录 ? ? ? ? ? ?在业务需要分页操作的时候、我们通常采用limit+order by这对洗剪吹组合、高端洋气上档次 ? ? ?然

很多时候、我们需要选择出从指定位置开始的指定行数、此时、limit笑了
? ? ?对于limit的定义是:
? ? ?limit x,y
? ? ?表示从第x行开始选择y条记录
? ? ?
? ? ?在业务需要分页操作的时候、我们通常采用limit+order by这对洗剪吹组合、高端洋气上档次
? ? ?然而、当翻到非常靠后的页面时、MySQL需要花费大量的时间来扫描需要丢弃的数据
? ? ?
? ? ?此时比较好的策略是使用 延迟关联
? ? ?通过使用覆盖索引查询返回需要的主键、再根据这些主键关联原表获得需要的行
? ? ?具体请看下面的一个例子
? ? ?

? ? ?假如有这样一个查询:

select film_id,actor,description from film where actor='WaterBin' order by title limit 100000,5

? ? ?我们可以这样改造:

select film.film_id,film.actor,film.description
  from film
inner join (
select film_id from film where f.actor='WaterBin'
 order by title limit 100000,5
           )
as f using(film_id);



By DBA_WaterBin

2013-08-02

Good Luck

作者:linwaterbin 发表于2013-8-2 21:04:42 原文链接

阅读:104 评论:0 查看评论

MySQL 优化Limit分页

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