您的位置:首页 > 数据库 > MySQL

mysql 分页性能优化

2016-01-23 09:16 615 查看
最简单的分页方法是这样的

select * from exarticletemp ORDER BY CreateDate desc LIMIT 10000,10


该表中存在5w左右数据

执行时间平均在10s左右,因此该种方式在数据量大的情况下查询效率极低。

优化方式有以下几种

1.此种方式平均在7-8s之间(CreateDate 需建立索引)

select * from exarticletemp where id> (SELECT id FROM exarticletemp ORDER BY CreateDate DESC LIMIT 10000,1)  ORDER BY CreateDate desc LIMIT 20


2.此种方式大概平均在0.01s

SELECT * FROM exarticletemp WHERE id BETWEEN 10000 AND 10020;


3.低于0.01s

select * from exarticletemp where id in(10109,10110,10111,10112,10113,10114,10115,10116,10117,10118,10119,10120,10121,10122,10123,10124,10125,10126,10127,10128,10129,10130)


4.低于1s

select B.* from (select Id from exarticletemp ORDER BY CreateDate LIMIT 20000,20) as A LEFT join exarticletemp B on A.Id =B.Id
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: