Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

328
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda