MySql大数据量查询limit与order by配合缓慢

时间:2020-12-25 13:04:20   收藏:0   阅读:0

大数据量在MySQL中查询分页排序,数据量就会很大

我们可以把limit与order by拆分为两个步骤 先根据条件 把limit、ordey by相关的数据的索引查出来,然后再根据索引查询具体的字段信息(也就是两层嵌套)

例:

select id,
user_name,
id,
user_name,
user_pwd,
real_name,
phone,
email,
locked,
deleted,
district_code,
last_password_change,
create_time,
update_time,
phone,
email,
update_time
from user
inner join (select id from user order by update_time desc limit 500,510) as users using (id)

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!