Re: Any optimizations to the join code in 7.1?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joel Burton <jburton(at)scw(dot)org>
Cc: "mascarm(at)mascari(dot)com" <mascarm(at)mascari(dot)com>, "'pgsql-hackers(at)postgresql(dot)org'" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Any optimizations to the join code in 7.1?
Date: 2001-04-25 21:32:12
Message-ID: 6243.988234332@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Joel Burton <jburton(at)scw(dot)org> writes:
> In other DB systems I've used, some find that for this original query:
> SELECT * FROM a, b WHERE a.id=b.id AND b.name = 'foo';
> that this version
> SELECT * FROM a JOIN b USING (id) WHERE b.name = 'foo';
> has slower performance than
> SELECT * FROM b JOIN a USING (id) WHERE b.name = 'foo';
> because it can reduce b before any join.

> Is it safe to assume that this is a valid optimization in PostgreSQL?

In general, that'd be a waste of time --- our planner considers the same
set of plans in either case.

However, it could make a difference if the planner thinks that the two
choices (a outer or b outer) have exactly the same cost. In that case
the order you wrote them in will influence which plan actually gets
picked; and if the planner's estimate is wrong --- ie, there really is a
considerable difference in the costs --- then you could see a change in
performance depending on which way you wrote it. That's a pretty
unusual circumstance, maybe, but it just happens that I'm in the middle
of looking at a planning bug wherein exactly this behavior occurs...

> If this whole thing were a view, except w/o the WHERE clause, and we were
> querying the view w/the b.name WHERE clause, would we still see a
> performance boost from the right arrangement? (ie, does our criteria get
> pushed down early enough in the joining process?)

Shouldn't make a difference; AFAIK the WHERE clause will get pushed down
as far as possible, independently of whether a view is involved or you
wrote it out the hard way.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Vince Vielhaber 2001-04-25 22:23:39 Re: refusing connections based on load ...
Previous Message Tom Lane 2001-04-25 21:14:56 Re: refusing connections based on load ...