Thread: INNER JOIN vs WHERE

INNER JOIN vs WHERE

From
"T. Alex Beamish"
Date:
Hello,

I've just had a quick search through the archives but couldn't find
what I wanted, so I've joined this list to continue my search for an
answer.

Is there any rule of thumb about how much more efficient an INNER JOIN
is compare to a regular WHERE statement?

I have a couple of queries in PostgreSQL that use a variety of tables
(four or five) linked together by key/foreign key conditions all ANDed
together. My co-worker re-wrote one of them using the INNER JOIN
approach and I wanted to find out if this would empirically improve the
performance.

I have not tried to do an EXPLAIN ANALYZE yet but I will try that.
Thanks for your responses.

Alex




Re: INNER JOIN vs WHERE

From
Tom Lane
Date:
"T. Alex Beamish" <talexb@tabsoft.on.ca> writes:
> Is there any rule of thumb about how much more efficient an INNER JOIN
> is compare to a regular WHERE statement?

Ideally there is no difference.  If there are only two tables involved,
there definitely is no difference.

If there is a difference, it's because there are more than two tables,
and the JOIN syntax forced a particular join order.  Read
http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=explicit-joins.html

Typically I'd expect JOIN syntax to be a loss because the odds are good
that you're forcing an inefficient join order.  It could be a win only
if the planner chooses a poor join order when given a free hand, or if
you have so many tables that you need to suppress the planner's search
for a good join order.

> I have not tried to do an EXPLAIN ANALYZE yet but I will try that.

If you have not bothered to do any EXPLAINs yet then you are really
wasting people's time on this list.

            regards, tom lane