pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tino Wildenhain <tino@wildenhain.de>
To: Mark Cotner <mcotner@yahoo.com>
Cc: Gavin Sherry <swm@alcove.com.au>
Cc: Dan Harris <fbsd@drivefaster.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: Speedier count(*)
Date: Thu, 11 Aug 2005 09:24:08 +0200
Message-ID: <1123745049.27613.1.camel@Andrea.peacock.de> (raw)
In-Reply-To: <BF204EF7.D9F6%mcotner@yahoo.com>
References: <BF204EF7.D9F6%mcotner@yahoo.com>

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.




view thread (12+ messages)  latest in thread

Message-ID: <1123745049.27613.1.camel@Andrea.peacock.de>
Permalink:  ../1123745049.27613.1.camel@Andrea.peacock.de/
Also on:    postgresql.org/message-id/1123745049.27613.1.camel@Andrea.peacock.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tino@wildenhain.de, mcotner@yahoo.com, swm@alcove.com.au, fbsd@drivefaster.net
  Subject: Re: Speedier count(*)
  In-Reply-To: <1123745049.27613.1.camel@Andrea.peacock.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox