Home > Database > Mysql Tutorial > mysql limit 优化分页查询_MySQL

mysql limit 优化分页查询_MySQL

WBOY
Release: 2016-06-01 13:12:50
Original
1112 people have browsed it

2014-5-28寒川计算机

最近做的一个网站谷歌站长工具提示sitemap访问超时,这是为毛原因呢?之前不是好好的么?进入mysql发现某个进程等待时间比较长,进一步发现原来是这样分页的mysql语句,因为文章比较多,而且是直接生成xml文件,全部笼统第调出所有文章aid,然后由php组和生成sitemap,我的分页mysql,类似如下:

select aid from articles order by aid limit 80000,4000
Copy after login
当然,前面几页数据还挺快的,上了一二十页后,等待的时间特别长。最终优化如下:
select aid fromarticleswhere aid >=(select aid from articles order by aid limit 80000,1) order byaid desc limit 4000
Copy after login

这样一来,效率瞬间提高。有木有?必须得有阿。

最后做个小总结:直接用limit分页查询,在数据量较小的情况下那是相当给力,随着翻页到后面,效率瞬间下降,于是用上面第二句可解决问题。此两句结合使用,将是天下无双了吧。

标签:mysqllimit优化sitemap

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template