Skip site navigation (1) Skip section navigation (2)

two queryes in a single tablescan

From: "Stefano Dal Pra" <s(dot)dalpra(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Cc: pgsql-performance(at)postgresql(dot)org
Subject: two queryes in a single tablescan
Date: 2007-10-17 12:30:52
Message-ID: 290a5abc0710170530v215cb2b0q4fa000ad43096a28@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-performancepgsql-sql
Hi everybody,

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.

This seems to me quite a common situation but i have no clue whether a neat
solution can be implemented through stored procedure.

Any hint?

Thank you

Stefano

Responses

pgsql-performance by date

Next:From: Heikki LinnakangasDate: 2007-10-17 13:00:58
Subject: Re: two queryes in a single tablescan
Previous:From: Stéphane SchildknechtDate: 2007-10-17 11:33:01
Subject: Re: Vacuum goes worse

pgsql-sql by date

Next:From: Heikki LinnakangasDate: 2007-10-17 13:00:58
Subject: Re: two queryes in a single tablescan
Previous:From: Sofer, YuvalDate: 2007-10-17 07:09:35
Subject: when inserting to table, text type parameter become NULL (after big assignment to this parameter)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group