limit and other joined tables

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: limit and other joined tables
Date: 2009-01-13 12:01:13
Message-ID: 20090113130113.6ba7e51a@dawn.webthatworks.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is the planner/optimiser smart enough to join just after the LIMIT
in a similar situation:

select [columns from A, B and C] from A
join B on A.Aid=B.Bid
join C on A.Aid=C.Cid
where (conditions on A and B columns)
order by [columns from A and B]
limit 10;

What about a similar situation with subselects?

select [columns from A, B, C] from (
select [column from A, B]
where (conditions on A and B columns)
) s
join C on s.Aid=C.Cid
order by [columns from A, B]
limit 10;

vs

select [columns from A, B, C] from (
select [column from A, B]
order by [columns from A, B]
limit 10
) s
join C on s.Aid=C.Cid;

Can postgresql take advantage of the LIMIT even if it is in the
outer select?

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

Browse pgsql-general by date

  From Date Subject
Next Message Emanuel Calvo Franco 2009-01-13 12:19:21 Re: Trying to create implicit casts to text in PG 8.3
Previous Message Dave Page 2009-01-13 09:44:02 Re: one-click installer in linux redhat-centos-fedora