Problem with subquery containg GROUP BY - Mailing list pgsql-sql

From Ishay Pomerantz
Subject Problem with subquery containg GROUP BY
Date
Msg-id 000401c4ed03$08a23730$92fadb3e@mazcal
Whole thread Raw
List pgsql-sql

Hi,

I’m using postgres 7.4.

 

I have two queries:

(1)

SELECT  a,b

FROM table1

WHERE a=99

 

(2)

SELECT  a,b,sum (o)  as sum_o

FROM table2

GROUP BY a,b

 

Both Runs very fast.

 

But when I try to make (2) as a subquery of (1):

 

SELECT  a,b,sum_o

FROM table1

LEFT JOIN  (

SELECT  a,b,sum (o)  as sum_o

                        FROM table2

GROUP BY a,b

) sub_query

USING (a,b)

WHERE a=99

 

 

It runs 100 times slower.

I guess it has to do with the postgres unable to pass the a=99 inside the subquery

 

Any ideas ?

 

ishay

pgsql-sql by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: [GENERAL] Get current trasanction id
Next
From: "Nathan Pickett"
Date:
Subject: Making a prepared statement in a stored procedure