pageHelper分页插件导致的查询慢的问题优化
首先在yml中配置
mybatis:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
会进行sql语句打印
问题:进行分页查询时pageHelper自动生成的count语句相当于在查询语句外包一层select count(1) from(你的查询语句)
对于你的查询语句的返回字段中有较多计算和较多字段返回时这个默认的查询语句效率较低
解决:id必须和你的分页查询id一致后面加_COUNT,查询条件可以抽取为公共的共两个sql语句使用,同时该sql不要定义mapper接口
<select id="findByPage_COUNT" resultType="long"> SELECT COUNT(1) FROM user <include refid="condition_sql" /> </select>

浙公网安备 33010602011771号