Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 97B306334C1 for ; Wed, 21 Oct 2009 09:16:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 93497-01 for ; Wed, 21 Oct 2009 12:16:04 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.188]) by mail.postgresql.org (Postfix) with ESMTP id C3B41633306 for ; Wed, 21 Oct 2009 09:16:11 -0300 (ADT) Received: from webserv.wug.de ([194.25.154.138]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0M8n1M-1N62hI3kR2-00CsiW; Wed, 21 Oct 2009 14:16:09 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1N0a6q-0000Mt-00 for pgsql-sql@postgresql.org; Wed, 21 Oct 2009 14:16:08 +0200 Date: Wed, 21 Oct 2009 14:16:08 +0200 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: report generation from table. Message-ID: <20091021121607.GA1086@a-kretschmer.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX1962OkwEjWdv9JjRxvrMtPrM6StVxOiH2Rd2qY vAfcuSmhONKyg/HemQU13UZD5F5VxoZpUyFVfVeKx0IkQ51aeO UgbXIEb4BogxRDHk1leHw== X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.344 tagged_above=-10 required=5 tests=AWL=-0.604, BAYES_20=-0.74 X-Spam-Level: X-Archive-Number: 200910/86 X-Sequence-Number: 33285 In response to sathiya psql : > Hi All, > > I have been searching for, Preparing report from a huge table. > > Queries am executing now are, > SELECT count(*) from HUGE_TBL where cond1, cond2; > SELECT count(*) from HUGE_TBL where cond1, cond3; > --- like this i have different conditions(10-15 different things ) and > different amount of conditions ( 2 - 5 condition ). > > As that is a very huge table, it took time to execute each query ( 2 min ). And > finally it takes 15 times that ( 30 min ).  Is there anyway to do the above > report efficiently ? > > Such executing the query only once, and getting all different outputs required > ? or fetching result from some cache ? select sum(case when and then 1 else 0 end) as query1, sum(case when and then 1 else 0 end) as query2, ... from table; It forces a whole seq. scan, but only once. Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)