We are using Spring Data with the PageRequest and hitting a significantly large set of data. All queries perform optimally except the query being executed to get the total number of pages. Is there a way to disable this feature or would we most likely have to implement our own Pageable?
Edit: After further analysis I believe the only way around this problem is to not use Spring Data and use EntityManager as it allows setting of start row and number of records to return. We only need whether next page is available so we just retrieve one extra record. We also need a dynamic query which doesn’t seem possible in Spring Data.
Edit 2: And it would seem I just didn’t wait long enough for some responses. Thanks guys!!!
The way to achieve this is simply by using
Listas return value. So for example for a repository defined like this:The query execution engine would apply the offset and pagesize as handed in by the
Pageablebut not trigger the additional count query as we don’t need to construct aPageinstance. This also documented in the relevant sections of the reference documentation.Update: If you want the next page / previous page of
Pagebut still skip the count query you may useSliceas the return value.