Re: count(*) slow on large tables

Christopher Kings-Lynne <chriskl@familyhealth.com.au>

From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
To: Jeff <threshar@torgo.978.org>
Cc: Christopher Browne <cbbrowne@acm.org>, "pgsql-performance@postgresql.org" <pgsql-performance@postgresql.org>
Date: 2003-10-04T09:37:32Z
Lists: pgsql-hackers, pgsql-performance
> On our message boards each post is a row.  The powers that be like to know
> how many posts there are total (In addition to 'today')-
> select count(*) from posts is how it has been
> done on our informix db.  With our port to PG I instead select reltuples
> pg_class.

We have exactly the same situation, except we just added a 'num_replies' 
field to each thread and a 'num_posts' field to each forum, so that 
getting that information out is a very fast operation.  Because, of 
course, there are hundreds of times more reads of that information than 
writes...

Chris