Re: Pagination count strategies - Mailing list pgsql-general

From Andrew Sullivan
Subject Re: Pagination count strategies
Date
Msg-id 20140403140018.GA58047@crankycanuck.ca
Whole thread Raw
In response to Pagination count strategies  (Leonardo M. Ramé <l.rame@griensu.com>)
Responses Re: Pagination count strategies  (Leonardo M. Ramé <l.rame@griensu.com>)
List pgsql-general
On Thu, Apr 03, 2014 at 10:34:32AM -0300, Leonardo M. Ramé wrote:
>
> What strategy for showing the total number of records returned do you
> recommend?.

The best answer for this I've ever seen is to limit the number of rows
you're counting (at least at first) to some reasonably small number --
say 5000.  This is usually reasonably fast for a well-indexed query,
and your pagination can say something like "First n of at least 5000
results", unless you have fewer than 5000 results, in which case you
know the number (and the count returned quickly anyway).  As you're
displaying those first 5000 results, you can work in the background
getting a more accurate number.  This is more work for your
application, but it provides a much better user experience (and you
can delay getting the detailed number until the user pages through to
the second page of results, so you don't count everything needlessly
in case the user just uses the first page, which IME happens a lot).
Note that even Google doesn't give you an accurate number -- they just
say "about ten trillion" or whatever.

Hope that's useful,

A

--
Andrew Sullivan
ajs@crankycanuck.ca


pgsql-general by date:

Previous
From: Leonardo M. Ramé
Date:
Subject: Pagination count strategies
Next
From: Alban Hertroys
Date:
Subject: Re: Pagination count strategies