Home > Database > Mysql Tutorial > body text

mysql大数据量分页慢问题解决方案

WBOY
Release: 2016-06-07 15:01:59
Original
1736 people have browsed it

1,要尽量少关联表 2,orderby 后面的字段要建索引,或者最好orderby后面跟id,这样会很快的。 3,对where 后面的条件中的关键字段 建索引,分页会快很多的。 下面中 agriculturalConditionReport_type有索引, 上面的根据time排序,下面的根据id排序。 执行

1,要尽量少关联表

2,orderby 后面的字段要建索引,或者最好orderby后面跟id,这样会很快的。

3,对where 后面的条件中的关键字段 建索引,分页会快很多的。


下面中

agriculturalConditionReport_type有索引, 上面的根据time排序,下面的根据id排序。
Copy after login
执行结果:


-- 测试数据条数300067


select 字段
from agritechnique.tab_agriculturalConditionReport agricultur0_ 
inner join tab_user_info userinfo1_ on agricultur0_.agriculturalConditionReport_userId=userinfo1_.user_id 
inner join sys_user_login_info userinfo1_1_ on userinfo1_.user_id=userinfo1_1_.user_id 
where agricultur0_.agriculturalConditionReport_type=1 order by agricultur0_.agriculturalConditionReport_time desc limit 3333, 25
-- (25 row(s)returned)
-- (2839 ms taken)


select 字段
inner join tab_user_info userinfo1_ on agricultur0_.agriculturalConditionReport_userId=userinfo1_.user_id 
inner join sys_user_login_info userinfo1_1_ on userinfo1_.user_id=userinfo1_1_.user_id 
where agricultur0_.agriculturalConditionReport_type=1 order by agricultur0_.agriculturalConditionReport_id desc limit 3333, 25
-- (25 row(s)returned)
-- (16 ms taken)
Copy after login



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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!