Let Parallel Append over simple UNION ALL have partial subpaths.
authorRobert Haas <rhaas@postgresql.org>
Fri, 23 Feb 2018 16:53:07 +0000 (11:53 -0500)
committerRobert Haas <rhaas@postgresql.org>
Thu, 8 Mar 2018 19:36:48 +0000 (14:36 -0500)
commit2c8672d1ac8028894afbf1777072c35305b249e2
treeaff149e68894c2750dd91fa24a7ead69d32f505d
parent960df2a9715c5c232b0f6f3effd40a3323eed6b0
Let Parallel Append over simple UNION ALL have partial subpaths.

A simple UNION ALL gets flattened into an appendrel of subquery
RTEs, but up until now it's been impossible for the appendrel to use
the partial paths for the subqueries, so we can implement the
appendrel as a Parallel Append but only one with non-partial paths
as children.

There are three separate obstacles to removing that limitation.
First, when planning a subquery, propagate any partial paths to the
final_rel so that they are potentially visible to outer query levels
(but not if they have initPlans attached, because that wouldn't be
safe).  Second, after planning a subquery, propagate any partial paths
for the final_rel to the subquery RTE in the outer query level in the
same way we do for non-partial paths.  Third, teach finalize_plan() to
account for the possibility that the fake parameter we use for rescan
signalling when the plan contains a Gather (Merge) node may be
propagated from an outer query level.

Patch by me, reviewed and tested by Amit Khandekar and Rajkumar
Raghuwanshi.  Test cases based on examples by Rajkumar Raghuwanshi.

Discussion: http://postgr.es/m/CA+Tgmoa6L9A1nNCk3aTDVZLZ4KkHDn1+tm7mFyFvP+uQPS7bAg@mail.gmail.com
src/backend/optimizer/path/allpaths.c
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/subselect.c
src/test/regress/expected/select_parallel.out
src/test/regress/sql/select_parallel.sql