Re: COUNT & Pagination

From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: "david(at)shadovitz(dot)com" <david(at)shadovitz(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>, "'Richard Huxton'" <dev(at)archonet(dot)com>
Subject: Re: COUNT & Pagination
Date: 2004-01-12 21:42:12
Message-ID: 1073943732.29178.153.camel@camel
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Mon, 2004-01-12 at 10:37, David Shadovitz wrote:
> > If you only need the count when you've got the results, most PG client
> > interfaces will tell you how many rows you've got. What language is your app
> > in?
>
> PHP.
> But I have only a subset of the results, retrieved via a query with a "LIMIT
> <m>" clause, so $pg_numrows is m.
> And retrieving all results (i.e. no LIMIT) is at least as expensive as
> COUNT(*).
>

Depending on frequency of updates and need for real time info, you could
cache the count in session as long as the user stays within the given
piece of your app.

Robert Treat
--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Shankar K 2004-01-12 21:45:45 Postgres on Netapp
Previous Message Greg Spiegelberg 2004-01-12 17:03:49 Re: failures on machines using jfs