Re: Much Ado About COUNT(*) - Mailing list pgsql-hackers

From Bruno Wolff III
Subject Re: Much Ado About COUNT(*)
Date
Msg-id 20050119161638.GA5725@wolff.to
Whole thread Raw
In response to Re: Much Ado About COUNT(*)  ("Mark Cave-Ayland" <m.cave-ayland@webbased.co.uk>)
Responses Re: Much Ado About COUNT(*)
List pgsql-hackers
On Wed, Jan 19, 2005 at 14:59:17 -0000, Mark Cave-Ayland <m.cave-ayland@webbased.co.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.


pgsql-hackers by date:

Previous
From: Travis P
Date:
Subject: Re: ARC patent
Next
From: Yann Michel
Date:
Subject: Caching of frequently used objects