I tested two queries for DB2 paging.
Table has 135000 records.
First one (hibernate default) - page one:
Code:
select * from (
select rownumber() over(order by this_.transm asc) as rownumber_, this_.* from online.transm this_ where (1=1) order by this_.transm asc ) as temp_ where rownumber_ <= 20
Execution time:3.79 secSecond query page one:
Code:
select * from transm this_ where (1=1) order by this_.transmsg asc fetch first 20 rows only
Execution time:1.1 sec
...
Execution time is better for second query for: page <5 (on this table)
When there is more records, pageNo increases and it is better to use second query for first N pages (in java we do ResultSet.next and return only results for page we need).
I tested on some tables and I have execution time (first query 30 seconds and second 4 seconds)
Is there a way to hibernate support this approach (maybe some parameter/true, false/), and than developer can decide when to use first and when second query.