Re: Propogating conditions into a query - Mailing list pgsql-general

From Tom Lane
Subject Re: Propogating conditions into a query
Date
Msg-id 14403.1118337436@sss.pgh.pa.us
Whole thread Raw
In response to Propogating conditions into a query  (Phil Endecott <spam_from_postgresql_general@chezphil.org>)
Responses Re: Propogating conditions into a query
Re: Propogating conditions into a query
List pgsql-general
Phil Endecott <spam_from_postgresql_general@chezphil.org> writes:
> I don't see anything in there about LEFT OUTER JOIN though.  Any ideas?

Oh, I missed that part of your message.  Hmm, I think the issue is that in

>> D join (M join G on (M.g=G.id)) on (D.id=M.b) where D.id=nnn

the planner deduces M.b=nnn by transitivity, but when the join is an
outer join it can't make the same deduction.

[ thinks some more... ]  If we distinguished conditions that hold below
the join from those that hold above it, we could deduce that M.b=nnn can
be enforced below the join even though it might not be true above it.
There's no such mechanism in existence now, though.

A possible workaround is to generate your query like

 D left join (M join G on (M.g=G.id)) on (D.id=M.b AND M.b=nnn) where D.id=nnn

but I don't know how practical that is for you.

            regards, tom lane

pgsql-general by date:

Previous
From: Phil Endecott
Date:
Subject: Re: Propogating conditions into a query
Next
From: Phil Endecott
Date:
Subject: Re: Propogating conditions into a query