Allow plan nodes with initPlans to be considered parallel-safe. If the plan itself is parallel-safe, and the initPlans are too, there's no reason anymore to prevent the plan from being marked parallel-safe. That restriction (dating to commit ab77a5a45) was really a special case of the fact that we couldn't transmit subplans to parallel workers at all. We fixed that in commit 5e6d8d2bb and follow-ons, but this case never got addressed.
We still forbid attaching initPlans to a Gather node that's inserted pursuant to debug_parallel_query = regress. That's because, when we hide the Gather from EXPLAIN output, we'd hide the initPlans too, causing cosmetic regression diffs. It seems inadvisable to kluge EXPLAIN to the extent required to make the output look the same, so just don't do it in that case. Along the way, this also takes care of some sloppiness about updating path costs to match when we move initplans from one place to another during createplan.c and setrefs.c. Since all the planning decisions are already made by that point, this is just cosmetic; but it seems good to keep EXPLAIN output consistent with where the initplans are. The diff in query_planner() might be worth remarking on. I found that one because after fixing things to allow parallel-safe initplans, one partition_prune test case changed plans (as shown in the patch) --- but only when debug_parallel_query was active. The reason proved to be that we only bothered to mark Result nodes as potentially parallel-safe when debug_parallel_query is on. This neglects the fact that parallel-safety may be of interest for a sub-query even though the Result itself doesn't parallelize. Discussion: https://postgr.es/m/1129530.1681317...@sss.pgh.pa.us Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/e08d74ca1342cb9e6047daad2019b550ecf54877 Modified Files -------------- src/backend/optimizer/plan/createplan.c | 15 +++-- src/backend/optimizer/plan/planmain.c | 15 +++-- src/backend/optimizer/plan/planner.c | 36 +++++++++--- src/backend/optimizer/plan/setrefs.c | 32 ++++++---- src/backend/optimizer/plan/subselect.c | 84 +++++++++++++++++++++------ src/backend/optimizer/util/pathnode.c | 18 +++++- src/include/optimizer/subselect.h | 3 + src/test/regress/expected/partition_prune.out | 37 +++++------- 8 files changed, 169 insertions(+), 71 deletions(-)