Skip to content

Commit a14a070

Browse files
committed
Fix assertion failure with incorrect number of workers
In 18~ (581df2148737), the previous code causes an assertion failure in the planner regarding the fact that a gather node should always have at least 1 worker to spawn, but we were initializing this number to 0 in pg_hint_plan when recalculating the number of workers to use for an AppendPath. So pg_hint_plan is wrong, and upstream is right, because a gather node should always ask for at least 1 parallel worker. Some tests of in ut-W are impacted here because this causes an increase in the number of workers to spawn, based on what max_parallel_workers_per_gather is set to. Note for v17 and older branches: this change has been originally applied as of 3c2e9c5, and has been backpatched to all the stable branches following issue #218, that reported that the same assertion failure can be reached, messing with the state of Gather node paths in the backend with an incorrect worker number compilation. Author: William Zhang, Michael Paquier Batchpatch-through: 13 Per issues #93 and #218.
1 parent 41e74f6 commit a14a070

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

expected/ut-W.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ Parallel()
12241224
QUERY PLAN
12251225
------------------------------------------------
12261226
Gather
1227-
Workers Planned: 1
1227+
Workers Planned: 2
12281228
-> Parallel Append
12291229
-> Parallel Seq Scan on p1_c2 p1_2
12301230
-> Parallel Seq Scan on p1_c4 p1_4

pg_hint_plan.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4832,13 +4832,17 @@ pg_hint_plan_set_rel_pathlist(PlannerInfo * root, RelOptInfo *rel,
48324832

48334833
foreach(lc, rel->partial_pathlist)
48344834
{
4835-
ListCell *lcp;
4836-
AppendPath *apath = (AppendPath *) lfirst(lc);
4837-
int parallel_workers = 0;
4835+
ListCell *lcp;
4836+
Node *path = (Node *) lfirst(lc);
4837+
AppendPath *apath;
4838+
int parallel_workers;
48384839

4839-
if (!IsA(apath, AppendPath))
4840+
if (!IsA(path, AppendPath))
48404841
continue;
48414842

4843+
apath = (AppendPath *) path;
4844+
parallel_workers = apath->path.parallel_workers;
4845+
48424846
foreach (lcp, apath->subpaths)
48434847
{
48444848
Path *spath = (Path *) lfirst(lcp);
@@ -4848,7 +4852,8 @@ pg_hint_plan_set_rel_pathlist(PlannerInfo * root, RelOptInfo *rel,
48484852
parallel_workers = spath->parallel_workers;
48494853
}
48504854

4851-
apath->path.parallel_workers = parallel_workers;
4855+
if (apath->path.parallel_workers < parallel_workers)
4856+
apath->path.parallel_workers = parallel_workers;
48524857
inhibit_nonparallel = true;
48534858
}
48544859

0 commit comments

Comments
 (0)