I want to know which of the below performs better in terms of time to execute query with 100k+ records
1) Oracle's Pagination
SELECT *
FROM (
SELECT id, col1, col2, rownum rn
FROM (
SELECT /*+ first_rows(50) */ id, col1, col2
FROM table1
ORDER BY id DESC
)
WHERE rownum <= 50
)
WHERE rn >= 20;
2) Pagination using MyBatis RowBounds.
MyBatis RowBounds uses normal JDBC and after firing the select it skips the first 20 records and then fetches the next 30 (pagesize).
Also, will the MyBatis approach become slower as the page number increases as more rows needs to be skipped?
In general, the JDBC driver would have to fetch the first 20 rows across the network so that will generally be less efficient than writing a pagination query. That penalty will grow larger as you fetch more pages.
Both approaches will, in general, get slower as you fetch subsequent pages. But that is normally not an issue-- if you are paging results, that implies that users aren't going to actually fetch more than a couple pages of results before they give up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With