I am interested to know if there is a more optimal way of getting the total rowcount from a JOOQ query before paginating with OFFSET and LIMIT
We tried using JOOQs synthetic SEEK clause however since our IDs are unordered UUIDs it does not work.
Our current implementation is to execute the query twice, the first time before we set an offset and limit to get the result/row count.
Then we get the results in the second query.
SelectQuery<Record> select = context.selectQuery();
select.addSelect(FOO_TABLE.fields());
select.addFrom(FOO_TABLE);
int totalElements = select.fetch().size();
select.addOffset(20);
select.addLimit(50));
List<Foo> paginatedFoo = select.fetchInto(Foo.class);
Is this just something that has to be accepted with this implementation/design, or is there any JDBC driver magic that would eliminate the need for two queries to be executed on the DB?
Any input or suggestions welcomed!