Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 729446335E3 for ; Thu, 7 Jan 2010 19:39:47 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 91233-03 for ; Thu, 7 Jan 2010 23:39:36 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from depesz.com (dave.depesz.com [78.46.78.198]) by mail.postgresql.org (Postfix) with ESMTP id B27CE6335D0 for ; Thu, 7 Jan 2010 19:39:36 -0400 (AST) Received: from depesz by depesz.com with local (Exim 4.69) (envelope-from ) id 1NT1wz-0005P8-Cy; Fri, 08 Jan 2010 00:39:33 +0100 Date: Fri, 8 Jan 2010 00:39:33 +0100 From: hubert depesz lubaczewski To: Lefteris Cc: pgsql-performance@postgresql.org Subject: Re: Air-traffic benchmark Message-ID: <20100107233933.GA19526@depesz.com> Reply-To: depesz@depesz.com References: <852badbc1001070438j36eb10d3qa22398ffcbef405f@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <852badbc1001070438j36eb10d3qa22398ffcbef405f@mail.gmail.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.189 tagged_above=-10 required=5 tests=BAYES_50=0.001, FH_DATE_PAST_20XX=3.188 X-Spam-Level: *** X-Archive-Number: 201001/127 X-Sequence-Number: 37007 On Thu, Jan 07, 2010 at 01:38:41PM +0100, Lefteris wrote: > airtraffic=# EXPLAIN ANALYZE SELECT "DayOfWeek", count(*) AS c FROM > ontime WHERE "Year" BETWEEN 2000 AND 2008 GROUP BY "DayOfWeek" ORDER > BY c DESC; Well, this query basically has to be slow. Correct approach to this problem is to add precalculated aggregates - either with triggers or with some cronjob. Afterwards query speed depends only on how good are your aggregates, and/or how detailed. Of course calculating them is not free, but is done on write (or periodically), and not on user-request, which makes user-requests *much* faster. depesz -- Linkedin: http://www.linkedin.com/in/depesz / blog: http://www.depesz.com/ jid/gtalk: depesz@depesz.com / aim:depeszhdl / skype:depesz_hdl / gg:6749007