Received: from sss.pgh.pa.us (sss.pgh.pa.us [209.114.132.154]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f2A34Qx61829 for ; Fri, 9 Mar 2001 22:04:26 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.1/8.11.1) with ESMTP id f2A33A913419; Fri, 9 Mar 2001 22:04:06 -0500 (EST) To: Stephan Szabo cc: David Olbersen , pgsql-sql@postgresql.org Subject: Re: Optimization via explicit JOINs In-reply-to: References: Comments: In-reply-to Stephan Szabo message dated "Fri, 09 Mar 2001 18:18:47 -0800" Date: Fri, 09 Mar 2001 22:03:10 -0500 Message-ID: <13416.984193390@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200103/214 X-Sequence-Number: 1868 Stephan Szabo 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