无论你是InnoD引擎LIMIT分页慢还是MyISAM引擎LIMIT分页慢,大伙SELECT查询分页一般都是这样的【数据总共2万条,需要查询3个字段】:
SELECT `id` , `url` , `content`FROM `product`WHERE 1ORDER BY `id`LIMIT 10000 , 100执行速度是: 45.7秒
哈哈,慢的掉渣吧!
MySql LIMIT 分页查询加速利器解决方案:
SELECT `id` , `url` , `content`FROM productINNER JOIN (SELECT `id`FROM productORDER BY `id`LIMIT 10000 , 100) AS product2USING ( id )执行速度是: 0 .03秒
大家以后就不要用传统的分页方法了,为什么这么快?我只想说4个字:、、复合索引。
本文章讨论SQL,都经过SQL_NO_CACHE和重启无数次Apache\MySql通过测试!
要用最新的分页优化加速器解决方案:
1.Mysql上亿万级分页慢加速器方法1
SELECT `id` FROM `product` WHERE 1 order by `id` limit 10000,100;
SELECT `id`,`url`,`content` FROM `product` WHERE `id` IN (上面搜索结果的id1,上面搜索结果的id2....上面搜索结果的id100);
2.Mysql千万级分页慢加速器方法2
SELECT `id` , `url` , `content` FROM product INNER JOIN (SELECT `id` FROM product ORDER BY `id` LIMIT 10000 , 100) AS product2 USING ( id );
3.Mysql百万级分页慢加速器方法3
SELECT `id` FROM `product` WHERE 1 order by `id` limit 10000,1;
SELECT `id`,`url`,`content` FROM `product` WHERE `id` >= 上面搜索结果的id LIMIT 100