Re: Any way to Convince postgres to push join clause inside subquery aggregate? - Mailing list pgsql-general

From Tom Lane
Subject Re: Any way to Convince postgres to push join clause inside subquery aggregate?
Date
Msg-id 21073.1062523881@sss.pgh.pa.us
Whole thread Raw
In response to Any way to Convince postgres to push join clause inside subquery aggregate?  (Greg Stark <gsstark@mit.edu>)
Responses Re: Any way to Convince postgres to push join clause inside subquery aggregate?
List pgsql-general
Greg Stark <gsstark@mit.edu> writes:
> slo=> explain
> select *
>  from (select foo_id,count(*) as n from foo_bar group by foo_id) as x
>  join (select * from foo limit 1) as foo using (foo_id)
> ;

Why not put the subselect in the output list, if that's the kind of plan
you want?

regression=# explain select foo.*, (select count(*) from foo_bar where foo_id = foo.foo_id) as n from foo;
                                     QUERY PLAN
------------------------------------------------------------------------------------
 Seq Scan on foo  (cost=0.00..17102.50 rows=1000 width=8)
   SubPlan
     ->  Aggregate  (cost=17.08..17.08 rows=1 width=0)
           ->  Index Scan using foobi on foo_bar  (cost=0.00..17.07 rows=5 width=0)
                 Index Cond: (foo_id = $0)
(5 rows)


            regards, tom lane

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Table name lengths...
Next
From: Ron Johnson
Date:
Subject: Re: Table name lengths...