由于pageHelper生成的sql语句含有子查询导致的sql执行效率太慢;其生成sql如下
SELECT SKIP ? FIRST ? * FROM (select xxx from table ) TEMP_T
;其语句中包含了子查询;我们需要将其改为没有子查询语句的sql 如下:
select SKIP ? FIRST ? xxx from table
修改过程如下:
在项目中新增如下类,注意包名,类名必须一致,才能覆盖原本jar中的类;
package com.github.pagehelper.dialect.helper;
import com.github.pagehelper.Page;
import com.github.pagehelper.dialect.AbstractHelperDialect;
import com.github.pagehelper.util.MetaObjectUtil;
import com.github.pagehelper.util.StringUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.cache.CacheKey;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.ParameterMapping;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.session.RowBounds;
public class InformixDialect extends AbstractHelperDialect {
@Override
public Object processPageParameter(
MappedStatement ms,
Map<String, Object> paramMap,
Page page,
BoundSql boundSql,
CacheKey pageKey) {
paramMap.put(PAGEPARAMETER_FIRST, page.getStartRow(