db2数据库分页查询优化:
select key, col1,col2 from (
select key, col1,col2 from table1 order by key desc fetch first 50 rows only
) order by key asc fetch first 10 rows only
其中50是最大的数据个数,10是每页个数
另外注意: 在mybatis中使用fetch first分页时,50和10不能参数化,不能如下SQL:
endIndex = 50; pageSize = 10
select key, col1,col2 from (
select key, col1,col2 from table1 order by key desc fetch first #{endIndex} rows only
) order by key asc fetch first #{pageSize} rows only
可以使用下列SQL:
String fetch1 = "fetch first 50 rows only";
String fetch2 = "fetch first 10 rows only";
select key, col1,col2 from (
select key, col1,col2 from table1 order by key desc ${fetch1}
) order by key asc ${fetch2}