大數據量在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)