Re: Any way to Convince postgres to push join clause inside subquery aggregate?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Any way to Convince postgres to push join clause inside subquery aggregate?
Date: 2003-09-02 17:31:21
Message-ID: 21073.1062523881@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Greg Stark <gsstark(at)mit(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris Bowlby 2003-09-02 17:33:00 Re: Table name lengths...
Previous Message Richard Huxton 2003-09-02 17:24:55 Re: Table name lengths...