From 7d8f6986b83c9a56f6ea11c959cdd8f52e1b543d Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Fri, 31 Mar 2017 21:01:20 -0400 Subject: Fix parallel query so it doesn't spoil row estimates above Gather. Commit 45be99f8cd5d606086e0a458c9c72910ba8a613d 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 --- src/backend/optimizer/util/pathnode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/backend/optimizer/util/pathnode.c') diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c index 999ebcee704..c6298072c9b 100644 --- a/src/backend/optimizer/util/pathnode.c +++ b/src/backend/optimizer/util/pathnode.c @@ -1742,16 +1742,17 @@ create_gather_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, required_outer); pathnode->path.parallel_aware = false; pathnode->path.parallel_safe = false; - pathnode->path.parallel_workers = subpath->parallel_workers; + pathnode->path.parallel_workers = 0; pathnode->path.pathkeys = NIL; /* Gather has unordered result */ pathnode->subpath = subpath; + pathnode->num_workers = subpath->parallel_workers; pathnode->single_copy = false; - if (pathnode->path.parallel_workers == 0) + if (pathnode->num_workers == 0) { - pathnode->path.parallel_workers = 1; pathnode->path.pathkeys = subpath->pathkeys; + pathnode->num_workers = 1; pathnode->single_copy = true; } -- cgit v1.2.3