Why is a paginated query slower than a plain one with Spring Data?

Viewed 5931

Given I have a simple query:

List<Customer> findByEntity(String entity);

This query returns 7k records in 700ms.

Page<Customer> findByEntity(String entity, Pageable pageable);

this query returns 10 records in 1080ms. I am aware of the additional count query for pagination, but still something seems off. Also one strange thing I've noticed is that if I increase page size from 10 to 1900, response time is exactly the same around 1080 ms.

Any suggestions?

2 Answers
Related