MySQL 限制 select 速度慢
可能的重复:
为什么 MYSQL 较高的 LIMIT 偏移量会减慢查询速度?< /a>
我有一个页面,我想根据每个帖子的票数从上到下对其中的帖子进行排序。
我有数百万条记录,查询变得非常慢。需要几分钟才能得到结果。
这很好:
SELECT `id` FROM `table` ORDER BY `votes` LIMIT 0,20;
这需要很长时间:
SELECT `id` FROM `table` ORDER BY `votes` LIMIT 100000,20;
我什至没有谈论将其设置为 1,000,000 或更多。
关于如何使其更快的任何想法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议每小时左右缓存一次结果。
http://www.addedbytes.com/for-beginners/output- caching-for-beginners/
我相信查询很重并且无论如何都会滞后,但是通过缓存,它将显示缓存的结果并每小时更新(运行查询)一次。
如果我错了,请纠正我。
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.