mybatis 分页插件卡,查询效率慢
使用mybatis分页的时候发现我的分页查询超慢也就几百万条数据,于是排除原因 步骤1:发现是排序导致查询慢; 步骤2:排序慢的原因:不是索引问题,是我的主表在分页前进行了联表查询;我滴天呐! 几百万条数据联表能快吗,关键是联表后不能通过索引排序了?这应该算是分页插件的bug了。强烈建议
1.page插件
PaginationInterceptor extends BaseInterceptor
2.mybatis部分
<sql id="getChgListSql"> select <include refid="webHtmlEvtColums"/> from tb_test t <where> <if test="startDate != null and startDate != "> AND t.update_date >= #{startDate} </if> </where> ORDER BY t.update_date desc </sql> <select id="getChgListPage" resultType="websiteHtmlEvent"> <include refid="getChgListSql"/> </select> <select id="getChgList" resultType="websiteHtmlEvent"> select <include refid="webHtmlEvtColums"/>, tb2.url as "url" from (<include refid="getChgListSql"/>) t inner join tb_url on tb1.url_id = tb2.id <where> <if test="url !=null and url != "> AND tb1.url_id in (select id from tb_web_url@DBLINK204 where url like %||#{url}||%) </if> </where> </select>
3.page对象里面添加一个属性
private String mapState;//联表查询sql方法名称
4.调用分页方法
evt.setPage(page); page.setMapState("com.xxx.xxxDao.xxxPage"); page.setList(dao.getChgList(evt));
然后就ok了