Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

334
Views
pagination with JOOQ

I'm trying to use JOOQ for paginating results from Mysql DB, I want to request my MySQL DB for a specific offset.

My Clients are requesting different sizes of results with different offsets and my service is stateless.

I don't want to use limit and offset since I know they have a bad performance.

    public void fetch() {
    Cursor<Record> cursor = null;

    String query = "books WHERE type = 'KIDS'";


    try {
        cursor = create.selectFrom(query).fetchLazy();

        while (cursor.hasNext()) {
            Record book = cursor.fetchNext();
        }
    }
    finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

How can I start from page 5 or from books 1000 to 1100?

Best Regards, Matan

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Performance wise, there's nothing wrong with LIMIT. It is true that OFFSET can lead to performance issues, because the skipped rows from OFFSET have to be processed by the database server just as if you actually fetched them, with the exception of not having to transfer them over the wire.

Having said so, your approach of trying to implement OFFSET in the Java client is much worse than implementing it in SQL. You do (at least) the same amount of work on the server side, while transferring much more data to the client just to discard it again. Just use OFFSET, in this case, if you must paginate to page 5.

A faster way to paginate is keyset pagination, which is supported by jOOQ via the SEEK clause. It is a different type of pagination, which doesn't allow to jump to page 5 very easily, only to the "next page" (such as e.g. the Twitter timeline).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!