X-Original-To: pgsql-performance@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E2CF6476304 for ; Wed, 16 Apr 2003 11:53:12 -0400 (EDT) Received: from mail.libertyrms.com (unknown [209.167.124.227]) by postgresql.org (Postfix) with ESMTP id 2674F476302 for ; Wed, 16 Apr 2003 11:53:07 -0400 (EDT) Received: from [10.1.2.130] (helo=dba2) by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) id 195pDk-0002Ot-00 for ; Wed, 16 Apr 2003 11:53:12 -0400 Received: by dba2 (Postfix, from userid 1019) id 60732CF00; Wed, 16 Apr 2003 11:53:12 -0400 (EDT) Date: Wed, 16 Apr 2003 11:53:12 -0400 From: Andrew Sullivan To: pgsql-performance@postgresql.org Subject: Re: for help! Message-ID: <20030416155312.GF19999@libertyrms.info> Mail-Followup-To: Andrew Sullivan , pgsql-performance@postgresql.org References: <200304160848.36431.josh@agliodbs.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200304160848.36431.josh@agliodbs.com> User-Agent: Mutt/1.5.3i X-Spam-Status: No, hits=-38.0 required=5.0 tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MUTT autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/143 X-Sequence-Number: 1649 On Wed, Apr 16, 2003 at 08:48:36AM -0700, Josh Berkus wrote: > Scott, > > > Well, you can always use the trick of putting an on insert / delete > > trigger on the table that maintains a single row table with the current > > count. That way, whenever a row is added or removed, the count is > BTW, I tested this for a client. I found the performance penalty > on inserts and updates to be: [. . .] > Please note that the effective performance penalty on inserts and > updates was dramatically higher for large batches of updates than > for small ones. Presumably the problem was to do with contention? This is why I don't really like the "update one row" approach for this sort of thing. But you _could_ write a trigger which inserts into a "staging" table, and write a little daemon which only updates the count table with the data from the staging table. It's a mighty ugly hack, but it ought to work. A -- ---- Andrew Sullivan 204-4141 Yonge Street Liberty RMS Toronto, Ontario Canada M2P 2A8 +1 416 646 3304 x110