Teach reparameterize_path() to handle AppendPaths.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 23 Jan 2018 21:50:34 +0000 (16:50 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 23 Jan 2018 21:50:34 +0000 (16:50 -0500)
commitbb94ce4d26c3b011c01bf44ab200334fea52b600
tree0aafab1431e5ce4be722d7471aecffbfdeaf8d20
parent95be5ce1bce3fdcf3ca0638baa12508e5b67ec17
Teach reparameterize_path() to handle AppendPaths.

If we're inside a lateral subquery, there may be no unparameterized paths
for a particular child relation of an appendrel, in which case we *must*
be able to create similarly-parameterized paths for each other child
relation, else the planner will fail with "could not devise a query plan
for the given query".  This means that there are situations where we'd
better be able to reparameterize at least one path for each child.

This calls into question the assumption in reparameterize_path() that
it can just punt if it feels like it.  However, the only case that is
known broken right now is where the child is itself an appendrel so that
all its paths are AppendPaths.  (I think possibly I disregarded that in
the original coding on the theory that nested appendrels would get folded
together --- but that only happens *after* reparameterize_path(), so it's
not excused from handling a child AppendPath.)  Given that this code's been
like this since 9.3 when LATERAL was introduced, it seems likely we'd have
heard of other cases by now if there were a larger problem.

Per report from Elvis Pranskevichus.  Back-patch to 9.3.

Discussion: https://postgr.es/m/5981018.zdth1YWmNy@hammer.magicstack.net
src/backend/optimizer/util/pathnode.c
src/test/regress/expected/join.out
src/test/regress/sql/join.sql