Spring datajpa paging query optimization

Viewed 697

When spring data JPA uses paging query and findall plus sorting, the query speed is quite slow when the data volume is too large. It is OK without sorting speed, but when turning pages, for example, Oracle uses rownum for paging, and the second page uses rownum > * and rownum < * for paging, the speed is also slow. Please ask if there is any way to optimize and improve the query speed

1 Answers

There is an alternative for offset based pagination: value based pagination.

Basically you use the key value(s) of the first/last row in the current page to find the next/previous row. See https://www.novatec-gmbh.de/en/blog/art-pagination-offset-vs-value-based-paging/ for details.

There is currently no support for this in Spring Data so you would have to roll your own with custom method implementations.

Related