Re: Planner Conceptual Error when Joining a Subquery -- Outer Query Condition not Pulled Into Subquery

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gavin Wahl <gavinwahl@gmail.com>
Cc: pgsql-performance@postgresql.org
Date: 2013-10-16T08:28:44Z
Lists: pgsql-performance
Gavin Wahl <gavinwahl@gmail.com> writes:
> It'd be nice if the planner could optimize the query (1) by turning it
> into (2). I understand that it might not be able to, but if it can pull
> the condition up in (3), why can't it in (4)?

(3) is an instance of seeing "a = b and b = c" and deducing "a = c" from
that.  (4) does not follow that pattern, so it's outside the realm of
what the planner can deduce.

In principle we could take "a = b and (b = c or b = d)" and deduce
"a = c or a = d" from that, but it'd be a lot more complication for a
lot less benefit than what we get from the existing logic.

			regards, tom lane