Commit 5ce5e4a1 authored by Robert Haas's avatar Robert Haas

Set consider_parallel correctly for upper planner rels.

Commit 3fc6e2d7 introduced new "upper"
RelOptInfo structures but didn't set consider_parallel for them
correctly, a point I completely missed when reviewing it.  Later,
commit e06a3896 made the situation
worse by doing it incorrectly for the grouping relation.  Try to
straighten all of that out.  Along the way, get rid of the annoying
wholePlanParallelSafe flag, which was only necessarily because of
the fact that upper planning stages didn't use paths at the time
that code was written.

The most important immediate impact of these changes is that
force_parallel_mode will provide useful test coverage in quite a few
more scenarios than it did previously, but it's also necessary
preparation for fixing some problems related to subqueries.

Patch by me, reviewed by Tom Lane.
parent 0daeba0e
......@@ -2018,7 +2018,6 @@ _outPlannerGlobal(StringInfo str, const PlannerGlobal *node)
WRITE_BOOL_FIELD(hasRowSecurity);
WRITE_BOOL_FIELD(parallelModeOK);
WRITE_BOOL_FIELD(parallelModeNeeded);
WRITE_BOOL_FIELD(wholePlanParallelSafe);
WRITE_BOOL_FIELD(hasForeignJoin);
}
......
......@@ -320,10 +320,6 @@ create_plan(PlannerInfo *root, Path *best_path)
*/
SS_attach_initplans(root, plan);
/* Update parallel safety information if needed. */
if (!best_path->parallel_safe)
root->glob->wholePlanParallelSafe = false;
/* Check we successfully assigned all NestLoopParams to plan nodes */
if (root->curOuterParams != NIL)
elog(ERROR, "failed to assign all NestLoopParams to plan nodes");
......
This diff is collapsed.
......@@ -2177,7 +2177,8 @@ create_projection_path(PlannerInfo *root,
pathnode->path.param_info = NULL;
pathnode->path.parallel_aware = false;
pathnode->path.parallel_safe = rel->consider_parallel &&
subpath->parallel_safe;
subpath->parallel_safe &&
!has_parallel_hazard((Node *) target->exprs, false);
pathnode->path.parallel_workers = subpath->parallel_workers;
/* Projection does not change the sort order */
pathnode->path.pathkeys = subpath->pathkeys;
......@@ -2304,6 +2305,16 @@ apply_projection_to_path(PlannerInfo *root,
gpath->subpath,
target);
}
else if (path->parallel_safe &&
has_parallel_hazard((Node *) target->exprs, false))
{
/*
* We're inserting a parallel-restricted target list into a path
* currently marked parallel-safe, so we have to mark it as no longer
* safe.
*/
path->parallel_safe = false;
}
return path;
}
......
......@@ -127,8 +127,6 @@ typedef struct PlannerGlobal
bool parallelModeNeeded; /* parallel mode actually required? */
bool wholePlanParallelSafe; /* is the entire plan parallel safe? */
bool hasForeignJoin; /* does have a pushed down foreign join */
} PlannerGlobal;
......
......@@ -575,6 +575,12 @@ select max(unique1) from tenk1 where unique1 > 42;
9999
(1 row)
-- the planner may choose a generic aggregate here if parallel query is
-- enabled, since that plan will be parallel safe and the "optimized"
-- plan, which has almost identical cost, will not be. we want to test
-- the optimized plan, so temporarily disable parallel query.
begin;
set local max_parallel_workers_per_gather = 0;
explain (costs off)
select max(unique1) from tenk1 where unique1 > 42000;
QUERY PLAN
......@@ -592,6 +598,7 @@ select max(unique1) from tenk1 where unique1 > 42000;
(1 row)
rollback;
-- multi-column index (uses tenk1_thous_tenthous)
explain (costs off)
select max(tenthous) from tenk1 where thousand = 33;
......
......@@ -234,9 +234,17 @@ select max(unique1) from tenk1 where unique1 < 42;
explain (costs off)
select max(unique1) from tenk1 where unique1 > 42;
select max(unique1) from tenk1 where unique1 > 42;
-- the planner may choose a generic aggregate here if parallel query is
-- enabled, since that plan will be parallel safe and the "optimized"
-- plan, which has almost identical cost, will not be. we want to test
-- the optimized plan, so temporarily disable parallel query.
begin;
set local max_parallel_workers_per_gather = 0;
explain (costs off)
select max(unique1) from tenk1 where unique1 > 42000;
select max(unique1) from tenk1 where unique1 > 42000;
rollback;
-- multi-column index (uses tenk1_thous_tenthous)
explain (costs off)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment