pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Stephan Szabo <sszabo@megazone23.bigpanda.com>
Cc: Nicolas Fertig <nfertig@swissnow.ch>
Cc: pgsql-sql@postgresql.org
Subject: Re: OUTER JOIN with filter
Date: Sun, 02 Mar 2003 02:09:17 -0500
Message-ID: <16210.1046588957@sss.pgh.pa.us> (raw)
In-Reply-To: <20030301170535.U21117-100000@megazone23.bigpanda.com>
References: <20030301170535.U21117-100000@megazone23.bigpanda.com>

Stephan Szabo <sszabo@megazone23.bigpanda.com> writes:
> On Sat, 1 Mar 2003, Nicolas Fertig wrote:
>> Can anyone help me with the problem bellow ?
>> 
>> SELECT TM.some_field, TS.name
>> FROM table_main TM
>> LEFT OUTER JOIN (SELECT name FROM table_slave WHERE c1 = 'myvalue') TS
>> USING(id)

> select tm.some_field, ts.name
> from table_main tm left outer join table_slave ts
> on (tm.id=ts.id and ts.c1='myvalue');

Offhand I believe that these queries should generate identical plans.
They do not at the moment --- the second one generates a worse plan
(sorry Stephan ;-)) --- because the planner does not realize it could
push down the ts.c1='myvalue' JOIN condition into the scan of ts, even
though the join is OUTER.  But AFAICS it would not change the results to
do so; ts rows failing ts.c1='myvalue' will not produce join output
anyway, but would allow outer-joined lefthand rows to be produced.  (Can
anyone see a hole in that logic?  It's on my to-do list to change it...)

I concur with the other comments that there's nothing wrong with the
given query ... other than such trivial details as it doesn't work ...
the sub-select doesn't produce an ID column.  So I think Nicolas is
giving us an over-censored description of his real problem; but without
the omitted details, we're not likely to offer much useful help.

			regards, tom lane



view thread (7+ messages)  latest in thread

Message-ID: <16210.1046588957@sss.pgh.pa.us>
Permalink:  ../16210.1046588957@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16210.1046588957@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, sszabo@megazone23.bigpanda.com, nfertig@swissnow.ch
  Subject: Re: OUTER JOIN with filter
  In-Reply-To: <16210.1046588957@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox