Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 890A02E0030 for ; Thu, 5 Jun 2008 13:08:49 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 35895-04 for ; Thu, 5 Jun 2008 13:08:42 -0300 (ADT) X-Greylist: delayed 00:25:23.316643 by SQLgrey-1.7.6 Received: from crestone.coronasolutions.com (crestone.coronasolutions.com [66.45.104.24]) by developer.postgresql.org (Postfix) with ESMTP id 186D52E002F for ; Thu, 5 Jun 2008 13:08:43 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by crestone.coronasolutions.com (Postfix) with ESMTP id 1ABA9ACC199; Thu, 5 Jun 2008 08:43:08 -0600 (MDT) Received: from crestone.coronasolutions.com ([127.0.0.1]) by localhost (crestone.coronasolutions.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 11561-04; Thu, 5 Jun 2008 08:43:07 -0600 (MDT) Received: from mac.local (dan-mac [10.1.250.4]) by crestone.coronasolutions.com (Postfix) with ESMTP id E303AACC18A for ; Thu, 5 Jun 2008 08:43:06 -0600 (MDT) Message-ID: <4848098A.5070500@drivefaster.net> Date: Thu, 05 Jun 2008 09:43:06 -0600 From: Dan Harris User-Agent: Thunderbird 2.0.0.14 (Macintosh/20080421) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: query performance question References: <4844F95B.4040009@m4n.nl> <31028.217.77.161.17.1212483874.squirrel@sq.gransy.com> In-Reply-To: <31028.217.77.161.17.1212483874.squirrel@sq.gransy.com> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at coronasolutions.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200806/34 X-Sequence-Number: 30384 tv@fuzzy.cz wrote: > > 3) Build a table with totals or maybe subtotals, updated by triggers. This > requires serious changes in application as well as in database, but solves > issues of 1) and may give you even better results. > > Tomas > > I have tried this. It's not a magic bullet. We do our billing based on counts from huge tables, so accuracy is important to us. I tried implementing such a scheme and ended up abandoning it because the summary table became so full of dead tuples during and after large bulk inserts that it slowed down selects on that table to an unacceptable speed. Even with a VACUUM issued every few hundred inserts, it still bogged down due to the constant churn of the inserts. I ended up moving this count tracking into the application level. It's messy and only allows a single instance of an insert program due to the localization of the counts in program memory, but it was the only way I found to avoid the penalty of constant table churn on the triggered inserts. -Dan