Re: inner join removal - Mailing list pgsql-hackers

From Tom Lane
Subject Re: inner join removal
Date
Msg-id 29364.1278614901@sss.pgh.pa.us
Whole thread Raw
In response to inner join removal  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: inner join removal
Re: inner join removal
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> Consider:

> SELECT * FROM foo LEFT JOIN (bar JOIN baz ON bar.y = baz.y) ON foo.x = bar.x;

> If foo is itty bitty and bar and baz are enormous, it would be nice to
> start by joining foo to bar and then joining the result to baz, but
> that's not legal.  However, if bar (y) references baz (y) and bar.y is
> not null, then the inner join is equivalent to a left join and it's OK
> to commute them.

I think you're going at this in the wrong place.  It'd likely work
better to identify this situation while building the SpecialJoinInfo
structs describing the join order constraints, and mark the constraints
appropriately.  In fact, I'm not convinced that "convert the inner join
to a left join" is even the right way to think about the problem,
because if you fail to get a win from it then you have likely made
things worse not better, by adding a join order constraint that wasn't
there before.  I think it might work out better if you ask "what
additional conditions are needed in order to prove that this inner join
can commute with this left join", and then work at being able to prove
that.  (It's entirely likely that the planner isn't currently gathering
the right information for solving that problem.)
        regards, tom lane


pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: [COMMITTERS] pgsql: Add note that using PL/Python 2 and 3 in the same session will
Next
From: Robert Haas
Date:
Subject: Re: inner join removal