]> granicus.if.org Git - postgresql/commit
Fix another oversight in checking if a join with LATERAL refs is legal.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 7 Dec 2015 22:41:45 +0000 (17:41 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 7 Dec 2015 22:41:45 +0000 (17:41 -0500)
commit0901d68babc324cc09077131fa966f15225e1fab
tree2268e522e8b3354d5553dd68ca2984499cb16da4
parent0cc6badf69f914667d3645af3e8d05e973542cb1
Fix another oversight in checking if a join with LATERAL refs is legal.

It was possible for the planner to decide to join a LATERAL subquery to
the outer side of an outer join before the outer join itself is completed.
Normally that's fine because of the associativity rules, but it doesn't
work if the subquery contains a lateral reference to the inner side of the
outer join.  In such a situation the outer join *must* be done first.
join_is_legal() missed this consideration and would allow the join to be
attempted, but the actual path-building code correctly decided that no
valid join path could be made, sometimes leading to planner errors such as
"failed to build any N-way joins".

Per report from Andreas Seltenreich.  Back-patch to 9.3 where LATERAL
support was added.
src/backend/optimizer/path/joinrels.c
src/backend/optimizer/util/relnode.c
src/include/optimizer/pathnode.h
src/test/regress/expected/join.out
src/test/regress/sql/join.sql