pgsql: Fix planner failure with full join in RHS of left join. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix planner failure with full join in RHS of left join.
Date
Msg-id E1atObx-0003NG-Tx@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix planner failure with full join in RHS of left join.

Given a left join containing a full join in its righthand side, with
the left join's joinclause referencing only one side of the full join
(in a non-strict fashion, so that the full join doesn't get simplified),
the planner could fail with "failed to build any N-way joins" or related
errors.  This happened because the full join was seen as overlapping the
left join's RHS, and then recent changes within join_is_legal() caused
that function to conclude that the full join couldn't validly be formed.
Rather than try to rejigger join_is_legal() yet more to allow this,
I think it's better to fix initsplan.c so that the required join order
is explicit in the SpecialJoinInfo data structure.  The previous coding
there essentially ignored full joins, relying on the fact that we don't
flatten them in the joinlist data structure to preserve their ordering.
That's sufficient to prevent a wrong plan from being formed, but as this
example shows, it's not sufficient to ensure that the right plan will
be formed.  We need to work a bit harder to ensure that the right plan
looks sane according to the SpecialJoinInfos.

Per bug #14105 from Vojtech Rylko.  This was apparently induced by
commit 8703059c6 (though now that I've seen it, I wonder whether there
are related cases that could have failed before that); so back-patch
to all active branches.  Unfortunately, that patch also went into 9.0,
so this bug is a regression that won't be fixed in that branch.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/80f66a9ad06eafa91ffc5ff19c725c7f393c242e

Modified Files
--------------
src/backend/optimizer/plan/initsplan.c | 25 ++++++++++++++++++++++++-
src/test/regress/expected/join.out     | 31 +++++++++++++++++++++++++++++++
src/test/regress/sql/join.sql          | 17 +++++++++++++++++
3 files changed, 72 insertions(+), 1 deletion(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix planner failure with full join in RHS of left join.
Next
From: Tom Lane
Date:
Subject: pgsql: Fix planner failure with full join in RHS of left join.