1

As select statement without an order by clause should be considered to have no particular order (see this question), it seems to be unreliable to use PagingAndSortingRepository.findAll(Pageable pageable), because there is no guarantee that each page will have unique rows. Is it so?

To elaborate on my concern, assume we have 20 rows with ids in range [1, 20]. Assume client makes request for the first page of size = 10, and gets rows with ids [1, 10]. Assume client makes a request for the second page. Expected result is to see rows with ids [11, 20]. However, since there is no guarantee on ordering, the second query is not guaranteed to return [11, 20], and can include any rows with ids [1, 10].

Is the concern valid?

1 Answers1

0

Order of data for findAll(Pageable pageable) depends on database if no sorting parameter used.

By using without sorting parameter in findAll(Pageable pageable) you can't add any condition on database query. You can just use OFFSET and LIMIT for pagination. So database always follows its default ordering on different pagination queries. Database maintains its default order with OFFSET and LIMIT query if ORDER BY or any condition not used.

So, it's completely okay to use PagingAndSortingRepository.findAll(Pageable pageable) with unsorted pageable.

Eklavya
  • 17,618
  • 4
  • 28
  • 57