1 oracle 分页
SELECT*FROM
( SELECTA.*, ROWNUM RN FROM(SELECT*FROM TABLE_NAME) A WHEREROWNUM<=40
) WHERERN>=21
前端往往传的是当前页和每页数量,后台算出起始索引和终止索引。
实际项目中oracle分页也是这么用mybatis写的。 可能数据量大了有别的优化写法。
2 mysql分页
select * from orders_history where type=8 limit10000,10;
百万条数据情况,以上查询需要3000ms。
select * from orders_history where type=8 and
id>=(select id from orders_history where type=8 limit 100000,1) limit 100;
这样优化需要1300ms。
select * from orders_history where type=2 and id between 1000000 and 1000100 limit 100;
这样就快了10ms左右
但是以上这种id必须是递增的。