Re: Optimization via explicit JOINs - Mailing list pgsql-sql

From Tom Lane
Subject Re: Optimization via explicit JOINs
Date
Msg-id 13416.984193390@sss.pgh.pa.us
Whole thread Raw
In response to Re: Optimization via explicit JOINs  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-sql
Stephan Szabo <sszabo@megazone23.bigpanda.com> writes:
> Actually, just thought of something else.  If you remove
> the probably redundant p.song_id=s.song_id from the second 
> query (since the join ... using should do that) does it
> change the explain output?

I was just about to point that out.  The WHERE clause *is* redundant
with the JOIN ... USING clause, but the planner will not recognize that,
and accordingly will multiply the estimated selectivity of the two
clauses together.  So the output row count for the JOIN form is
misleadingly small.  If you remove the redundant WHERE clause then you
should get identical planning estimates for both forms of the query.

The planner does actually recognize and discard duplicate qualifiers
that appear in the same place (eg, WHERE p.song_id=s.song_id AND
p.song_id=s.song_id) but it's not so smart about qualifiers that are
in different parts of the query...
        regards, tom lane


pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Optimization via explicit JOINs
Next
From: Andrew Perrin
Date:
Subject: recompiling to use gnu readline?