Re: Much Ado About COUNT(*)

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Mark Cave-Ayland <m(dot)cave-ayland(at)webbased(dot)co(dot)uk>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Much Ado About COUNT(*)
Date: 2005-01-19 16:16:38
Message-ID: 20050119161638.GA5725@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jan 19, 2005 at 14:59:17 -0000,
Mark Cave-Ayland <m(dot)cave-ayland(at)webbased(dot)co(dot)uk> wrote:
> BEGIN;
> INSERT INTO person (first_name, .... Tel) VALUES ('Fred', ....
> '12345');
> INSERT INTO person_count(id) VALUES (currval('id_seq'));
> COMMIT;
>
>
> So then I would use SELECT COUNT(*) FROM person_count whenever I wanted to
> know the current number of person records. How much quicker would a COUNT(*)
> be if visibility were included in the indices as opposed to a "hacked"
> approach like this?

You are only going to get a constant factor speed up unless the space savings
allows much better use of cache. You probably want to look at using
triggers to maintain counts in another table.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Yann Michel 2005-01-19 16:44:00 Caching of frequently used objects
Previous Message Travis P 2005-01-19 15:33:12 Re: ARC patent