Uploaded image for project: 'Spring Data JPA'
  1. Spring Data JPA
  2. DATAJPA-124

findAll(Pageable pageable) should not issue a second query when SELECT COUNT() returns 0

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0.1
    • Fix Version/s: 1.1 RC1
    • Component/s: Core
    • Labels:
      None

      Description

      findAll() first queries the number of records in a table (to return the total number in a Page) and then queries requested page. If the first query returns 0 (empty table), the second query is pointless as it will always return an empty list. Please see patch: https://github.com/nurkiewicz/spring-data-jpa/commit/dd0a213ecd298d4886659213cf8d78de8ad16919 and pull-request: https://github.com/SpringSource/spring-data-jpa/pull/12.

      Actually we might consider even more aggressive optimizations, e.g. if user requests second page with size 10 (records 11-20) but there are only 9 records in the database, querying the database is unnecessary as well.

        Attachments

          Activity

            People

            • Assignee:
              olivergierke Oliver Gierke
              Reporter:
              nurkiewicz Tomasz Nurkiewicz
              Last updater:
              Trevor Marshall
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: