On Thu, Oct 22, 2015 at 2:49 PM, Robert Haas <robertmh...@gmail.com> wrote:
> On Thu, Oct 22, 2015 at 1:38 PM, Tom Lane <t...@sss.pgh.pa.us> wrote:
>> Um ... why would you not want the projections to happen in the child
>> nodes, where they could be parallelized?  Or am I missing something?
> You probably would, but sometimes that might not be possible; for
> example, the tlist might contain a parallel-restricted function (which
> therefore has to run in the leader).

And here's a (rather small) patch to push target-list evaluation down
to the worker whenever possible.  With this, if you do something like

SELECT aid + bid FROM pgbench_accounts WHERE aid % 10000 = 0;

...then aid + bid can be calculated in the workers rather than in the
leader.  Unfortunately, if you do this...

SELECT sum(aid + bid) FROM pgbench_accounts WHERE aid % 10000 = 0;

...then it doesn't help, because make_subplanTargetList() thinks it
may as well just pull aid and bid out of the join nest and then do the
sum during the aggregation stage.  Presumably if we get the parallel
aggregation stuff working then this will get fixed, because there will
be a Partial Aggregate step before the Gather.  But whether that gets
into 9.6 or not, this seems like a useful step forward.

Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index a3cc274..3252904 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -1985,6 +1985,22 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
 					 * the desired tlist.
 					result_plan->targetlist = sub_tlist;
+					/*
+					 * If the plan happens to be a Gather plan, and the
+					 * subplan is projection-capable, then insert the tlist
+					 * there, too, so that the workers can help with
+					 * projection.  But if there is something that is not
+					 * parallel-safe in the tlist, then we can't.
+					 */
+					if (IsA(result_plan, Gather))
+					{
+						Plan	   *outer_plan = outerPlan(result_plan);
+						if (is_projection_capable_plan(outer_plan) &&
+							!has_parallel_hazard((Node *) sub_tlist, false))
+							outer_plan->targetlist = sub_tlist;
+					}
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:

Reply via email to