Even assuming that there is an efficient query that retrieves both the record of the record and the pages themselves, paginated, you will need to make an additional call to db for each page that the user accesses. And this would make the performance gain gained by accessing the first page insignificant.
I mean the following: to access the first page you need:
- total number of filtered items without pagination
- paginated filtered items for page 1
To access other pages, you no longer need a counting request. You only need the filtered elements for page x.
After expanding n pages, even using the optimization you are looking for, you made n calls instead of n + 1 calls of the non-optimized version. Therefore, I would not spend too much time thinking about it.
You only need to be careful in your implementation so as not to execute the record counter when it is not needed: you need it only after the user changes the filtering.
source share