X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 607E0D1C7F0 for ; Sun, 23 May 2004 18:41:46 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 49999-03 for ; Sun, 23 May 2004 18:41:26 -0300 (ADT) Received: from smtp.istop.com (dci.doncaster.on.ca [66.11.168.194]) by svr1.postgresql.org (Postfix) with ESMTP id 1B5BFD1CECC for ; Sun, 23 May 2004 18:36:07 -0300 (ADT) Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) by smtp.istop.com (Postfix) with SMTP id 9FFA117C077; Sun, 23 May 2004 17:36:08 -0400 (EDT) To: pgsql-general@postgresql.org Subject: Re: how many record versions References: <40AFAD9F.6000104@zara.6.isreserved.com> <40B0D230.6030803@zara.6.isreserved.com> In-Reply-To: <40B0D230.6030803@zara.6.isreserved.com> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 23 May 2004 17:36:07 -0400 Message-ID: <87vfimq114.fsf@stark.xeocode.com> Lines: 39 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200405/716 X-Sequence-Number: 61150 David Garamond writes: > Actually, each record will be incremented probably only thousands of times a > day. But there are many banners. Each record has a (bannerid, campaignid, > websiteid, date, countrycode) "dimensions" and (impression, click) "measures". In the past when I had a very similar situation we kept the raw impression and click event data. Ie, one record per impression in the impression table and one record per click in the click data. That makes the tables insert-only which is efficient and not prone to locking contention. They would never have to be vacuumed except after purging old data. Then to accelerate queries we had denormalized aggregate tables with a cron job that did the equivalent of insert into agg_clicks ( select count(*),bannerid from clicks where date between ? and ? group by bannerid ) Where the ?s were actually hourly periods. Ie, at 12:15 it ran this query for the 11-12 period. This meant we didn't have immediate up-to-date stats on banners but it meant we did have stats on every single impression and click including time and information about the users. This worked out very well for reporting needs. If your system is using the data to handle serving the ads, though, it's a different kettle of fish. For that I think you'll want something that avoids having to do a database query for every single impression. -- greg