Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fb1879c

Browse files
committed
Fix parallel query so it doesn't spoil row estimates above Gather.
Commit 45be99f removed GatherPath's num_workers field, but this is entirely bogus. Normally, a path's parallel_workers flag is supposed to indicate the number of workers that it wants, and should be 0 for a non-partial path. In that commit, I mistakenly thought that GatherPath could also use that field to indicate the number of workers that it would try to start, but that's disastrous, because then it can propagate up to higher nodes in the plan tree, which will then get incorrect rowcounts because the parallel_workers flag is involved in computing those values. Repair by putting the separate field back. Report by Tomas Vondra. Patch by me, reviewed by Amit Kapila. Discussion: http://postgr.es/m/f91b4a44-f739-04bd-c4b6-f135bd643669@2ndquadrant.com
1 parent 9b6e8d8 commit fb1879c

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

src/backend/nodes/outfuncs.c

+1
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,7 @@ _outGatherPath(StringInfo str, const GatherPath *node)
17951795

17961796
WRITE_NODE_FIELD(subpath);
17971797
WRITE_BOOL_FIELD(single_copy);
1798+
WRITE_INT_FIELD(num_workers);
17981799
}
17991800

18001801
static void

src/backend/optimizer/plan/createplan.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ create_gather_plan(PlannerInfo *root, GatherPath *best_path)
13951395

13961396
gather_plan = make_gather(tlist,
13971397
NIL,
1398-
best_path->path.parallel_workers,
1398+
best_path->num_workers,
13991399
best_path->single_copy,
14001400
subplan);
14011401

src/backend/optimizer/util/pathnode.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1681,16 +1681,17 @@ create_gather_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath,
16811681
required_outer);
16821682
pathnode->path.parallel_aware = false;
16831683
pathnode->path.parallel_safe = false;
1684-
pathnode->path.parallel_workers = subpath->parallel_workers;
1684+
pathnode->path.parallel_workers = 0;
16851685
pathnode->path.pathkeys = NIL; /* Gather has unordered result */
16861686

16871687
pathnode->subpath = subpath;
1688+
pathnode->num_workers = subpath->parallel_workers;
16881689
pathnode->single_copy = false;
16891690

1690-
if (pathnode->path.parallel_workers == 0)
1691+
if (pathnode->num_workers == 0)
16911692
{
1692-
pathnode->path.parallel_workers = 1;
16931693
pathnode->path.pathkeys = subpath->pathkeys;
1694+
pathnode->num_workers = 1;
16941695
pathnode->single_copy = true;
16951696
}
16961697

src/include/nodes/relation.h

+1
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,7 @@ typedef struct GatherPath
11891189
Path path;
11901190
Path *subpath; /* path for each worker */
11911191
bool single_copy; /* path must not be executed >1x */
1192+
int num_workers; /* number of workers sought to help */
11921193
} GatherPath;
11931194

11941195
/*

0 commit comments

Comments
 (0)