Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id DE0919FA06F; Sat, 20 Oct 2007 13:31:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 78206-10; Sat, 20 Oct 2007 13:31:37 -0300 (ADT) X-Greylist: delayed 01:23:20.779523 by SQLgrey-1.7.5 X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail.logix-tt.com (mail.logix-tt.com [212.211.145.186]) by postgresql.org (Postfix) with ESMTP id 59CB09FA06C; Sat, 20 Oct 2007 13:31:43 -0300 (ADT) Received: from kingfisher.intern.logix-tt.com (p549D20BD.dip0.t-ipconnect.de [84.157.32.189]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id B92AA65217; Sat, 20 Oct 2007 12:58:43 +0200 (CEST) Received: from kingfisher.sec.intern.logix-tt.com (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id 8893E16B0CA; Sat, 20 Oct 2007 12:58:24 +0200 (CEST) Date: Sat, 20 Oct 2007 12:58:24 +0200 From: Markus Schaber To: "Stefano Dal Pra" Cc: pgsql-sql@postgresql.org, pgsql-performance@postgresql.org Subject: Re: [SQL] two queryes in a single tablescan Message-ID: <20071020125824.75df357c@kingfisher.sec.intern.logix-tt.com> In-Reply-To: <290a5abc0710170530v215cb2b0q4fa000ad43096a28@mail.gmail.com> References: <290a5abc0710170530v215cb2b0q4fa000ad43096a28@mail.gmail.com> Organization: www.logix-tt.com X-Mailer: Claws Mail 2.10.0 (GTK+ 2.10.13; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.03 tagged_above=0 required=5 tests=AWL=0.029, BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200710/235 X-Sequence-Number: 27257 Hi, Stefano, "Stefano Dal Pra" wrote: > suppose you have a large table tab and two (or more) queryes like this: > > SELECT count(*),A FROM tab WHERE C GROUP BY A; > SELECT count(*),B FROM tab WHERE C GROUP BY B; > > is there any way to get both results in a single query, > eventually through stored procedure? > The retrieved [count(*),A] ; [count(*),B)] data couldnt fit > on a single table, of course. > > The main goal would be to get multiple results while scanning the > table[s] once only > thus getting results in a faster way. PostgreSQL 8.3 contains great improvements in this area, you can simply start the selects from concurrent connections, and the backend will synchronize the scans. Regards, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in Europe! www.ffii.org www.nosoftwarepatents.org