简体   繁体   中英

MyBatis RowBounds vs Oracle pagination query using rownum and nested subquery

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM