mybatis 分页插件卡,查询效率慢


使用mybatis分页的时候发现我的分页查询超慢也就几百万条数据,于是排除原因
步骤1:发现是排序导致查询慢;
步骤2:排序慢的原因:不是索引问题,是我的主表在分页前进行了联表查询;我滴天呐!
几百万条数据联表能快吗,关键是联表后不能通过索引排序了
?这应该算是分页插件的bug了。强烈建议

大神升级分页插件。
步骤3:改造分页插件;思路中间绕的路就不说了。在mybatis里面写两个查询,一个主表查询用于分页
一个是主表联表查询;在分页插件中先调用主表查询sql进行分页;然后把主表联表查询sql中的主表查询
部分替换。
下面是代码截图

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了


版权声明:本文为songqiang2011原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。