My Sql 高效分页

时间:2023-03-09 15:13:31
My Sql 高效分页
/*
*普通分页
*在数据文件上偏移1000000查出10条
*/ select *
from zoldesk_92game_net_ecms_bj
where classid=303
ORDER BY id ASC
LIMIT 1000000,10 ; /*
*高效分页
*1、在索引上查出起始索引
*2、从起始索引上查出10条
*/ SELECT * from zoldesk_92game_net_ecms_bj WHERE id >=
(
SELECT id
FROM zoldesk_92game_net_ecms_bj
where classid=303
ORDER BY id ASC
LIMIT 1000000, 1
)
and classid=303
ORDER BY id ASC
LIMIT 10 ;

这是楼下的办法

SELECT * from zoldesk_92game_net_ecms_bj WHERE id in
(
SELECT id from
(
SELECT id
FROM zoldesk_92game_net_ecms_bj
where classid=303
ORDER BY id ASC
LIMIT 1000000, 10
)
AS temp
)