746 Star 2.8K Fork 834

abel533 / Mybatis_PageHelper

 / 详情

使用PageHelper查询页数较高时用时长,使用方式不对吗?

已完成
创建于  
2018-02-08 16:32

环境:mybatis+Oracle数据库 目标表里有240万条记录 目的:查询第60000页,25条记录

打印查询耗时

Long tiem1 = System.currentTimeMillis();

List<Mtsend_Info> mtsend_infos = infoMapper.selectByParam(sql);

System.out.print("耗时" + (System.currentTimeMillis() - tiem1) + "ms\n");

1.不用PageHelper,使用手动划分rownum 耗时831ms

02-0816:31:36[com.hengkang.app.mappers.Mtsend_InfoMapper.selectByParam-142][http-bio-8080-exec-3][45168] - ==> Preparing: select oidnew,to_char(putintime,'yyyy-mm-dd HH:mi:ss') timestr1,putintime,phone,msgcont,uc,channelid,pri,pknum,pktotal,state,feenum,submitmsgid,rptstate,rptinfo,to_char(rptrecvtime,'yyyy-mm-dd HH:mi:ss') timestr2,to_char(submittime,'yyyy-mm-dd HH:mi:ss') timestr3,chpri,linkid from(select a.*,rownum ro from HKSMGATEWAY_SMS.mtsend_info a where rownum <=1500000) where ro >1499975
02-0816:31:36[com.hengkang.app.mappers.Mtsend_InfoMapper.selectByParam-142][http-bio-8080-exec-3][45169] - ==> Parameters:
02-0816:31:36[com.hengkang.app.mappers.Mtsend_InfoMapper.selectByParam-142][http-bio-8080-exec-3][45998] - <== Total: 25
耗时831ms

2.使用PageHelper 耗时4477ms

Integet pageSize=25;
Integer start = (page - 1) * pageSize;
PageHelper.startPage(page, pageSize);

02-0816:28:44[com.hengkang.app.mappers.Mtsend_InfoMapper.selectByParam-142][http-bio-8080-exec-9][420872] - ==> Preparing: select * from ( select tmp_page.*, rownum row_id from ( select oidnew,to_char(putintime,'yyyy-mm-dd HH:mi:ss') timestr1,putintime,phone,msgcont,uc,channelid,pri,pknum,pktotal,state,feenum,submitmsgid,rptstate,rptinfo,to_char(rptrecvtime,'yyyy-mm-dd HH:mi:ss') timestr2,to_char(submittime,'yyyy-mm-dd HH:mi:ss') timestr3,chpri,linkid from HKSMGATEWAY_SMS.mtsend_info ) tmp_page where rownum <= ? ) where row_id > ?
02-0816:28:44[com.hengkang.app.mappers.Mtsend_InfoMapper.selectByParam-142][http-bio-8080-exec-9][420873] - ==> Parameters: 1500000(Integer), 1499975(Integer)
02-0816:28:48[com.hengkang.app.mappers.Mtsend_InfoMapper.selectByParam-142][http-bio-8080-exec-9][425087] - <== Total: 25
耗时4477ms

评论 (1)

有我无碍 创建了任务
有我无碍 更新了任务
有我无碍 更新了任务
有我无碍 更新了任务
有我无碍 更新了任务
有我无碍 更新了任务
有我无碍 更新了任务

查询第60000页。

一般数据库都会查询出前60000页然后舍弃,因此这是一个非常耗时的操作。

大数据量进行分页时,应该通过排序和条件对下一页的数据进行限制。每次查询时,都查第一页的N条数据。

abel533 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
8363 free 1578914558
Java
1
https://gitee.com/free/Mybatis_PageHelper.git
git@gitee.com:free/Mybatis_PageHelper.git
free
Mybatis_PageHelper
Mybatis_PageHelper

搜索帮助