开发者

Slow MySQL limit select [duplicate]

开发者 https://www.devze.com 2023-04-03 19:34 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Why does MYSQL higher LIMIT offset slow the query down?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Why does MYSQL higher LIMIT offset slow the query down?

I have a page and I would like to sort posts in it from top to bottom by the amount of votes each post has.

I have millions of records, and the query gets really slow. it takes few good minutes to get the results.

This is fine:

SELECT `id` FROM `table` ORDER BY开发者_开发知识库 `votes` LIMIT 0,20;

This will take ages:

SELECT `id` FROM `table` ORDER BY `votes` LIMIT 100000,20;

I am not even talking about setting it to 1,000,000 and more.

Any ideas on how to make this faster?


I recommend caching the result every hour or so.

http://www.addedbytes.com/for-beginners/output-caching-for-beginners/

I believe the query is heavy and will lagg anyway, but with caching it'll show cached result and update (run query) once a hour.

Correct me, if I'm wrong.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号