Re: Speedier count(*)

From: Tino Wildenhain <tino(at)wildenhain(dot)de>
To: Mark Cotner <mcotner(at)yahoo(dot)com>
Cc: Gavin Sherry <swm(at)alcove(dot)com(dot)au>, Dan Harris <fbsd(at)drivefaster(dot)net>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Speedier count(*)
Date: 2005-08-11 07:24:08
Message-ID: 1123745049.27613.1.camel@Andrea.peacock.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Am Donnerstag, den 11.08.2005, 00:40 -0400 schrieb Mark Cotner:
> Here's a trigger I wrote to perform essentially the same purpose. The nice
> thing about this is it keeps the number up to date for you, but you do incur
> slight overhead.
...
>
> CREATE TRIGGER del_rowcount_tr BEFORE DELETE ON test FOR EACH ROW EXECUTE
> PROCEDURE del_rowcount();
> CREATE TRIGGER add_rowcount_tr BEFORE INSERT ON test FOR EACH ROW EXECUTE
> PROCEDURE add_rowcount();
>
> INSERT INTO rowcount (tablename) VALUES ('test');
...

beware of problems with concurrency and even what happens
if transactions roll back. Maybe you can "fix" it a bit
by regulary correcting the count via cronjob or so.

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Gavin Sherry 2005-08-11 10:36:58 Re: Speedier count(*)
Previous Message Chun Yit(Chronos) 2005-08-11 07:03:30 Re: it is always delete temp table will slow down the postmaster?