Re: [PERFORM] two queryes in a single tablescan

2007-10-17 Thread 李彦 Ian Li
I remember when I was using SQL server we did like like that: SELECT count(CASE WHEN A THEN 1 END) AS cnt_a, count(CASE WHEN B THEN 1 END) AS cnt_b FROM tab WHERE C; I did a little test with pg_bench data, also works in PostgreSQL: test=# select count(*) from history where tid = 1; count ---

Re: [PERFORM] two queryes in a single tablescan

2007-10-17 Thread Heikki Linnakangas
Steinar H. Gunderson wrote: > On Wed, Oct 17, 2007 at 02:30:52PM +0200, Stefano Dal Pra wrote: >> The main goal would be to get multiple results while scanning the >> table[s] once only >> thus getting results in a faster way. > > In 8.3, Postgres will do this for you itself -- if you already hav

Re: [PERFORM] two queryes in a single tablescan

2007-10-17 Thread Stefano Dal Pra
On 10/17/07, Heikki Linnakangas <[EMAIL PROTECTED]> wrote: > 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 b

Re: [PERFORM] two queryes in a single tablescan

2007-10-17 Thread Steinar H. Gunderson
On Wed, Oct 17, 2007 at 02:30:52PM +0200, Stefano Dal Pra wrote: > The main goal would be to get multiple results while scanning the > table[s] once only > thus getting results in a faster way. In 8.3, Postgres will do this for you itself -- if you already have a sequential scan running against a

Re: [PERFORM] two queryes in a single tablescan

2007-10-17 Thread Heikki Linnakangas
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? >

[PERFORM] two queryes in a single tablescan

2007-10-17 Thread Stefano Dal Pra
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(*)