fix_row_est_pa_v1.patch
application/octet-stream
Filename: fix_row_est_pa_v1.patch
Type: application/octet-stream
Part: 0
Message:
Re: Observations in Parallel Append
Patch
Format: unified
Series: patch v1
| File | + | − |
|---|---|---|
| src/backend/executor/nodeAppend.c | 3 | 4 |
| src/backend/optimizer/path/costsize.c | 10 | 4 |
diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c
index 0e93713..3920f53 100644
--- a/src/backend/executor/nodeAppend.c
+++ b/src/backend/executor/nodeAppend.c
@@ -446,10 +446,9 @@ choose_next_subplan_for_leader(AppendState *node)
*
* We start from the first plan and advance through the list;
* when we get back to the end, we loop back to the first
- * nonpartial plan. This assigns the non-partial plans first
- * in order of descending cost and then spreads out the
- * workers as evenly as possible across the remaining partial
- * plans.
+ * partial plan. This assigns the non-partial plans first in
+ * order of descending cost and then spreads out the workers
+ * as evenly as possible across the remaining partial plans.
* ----------------------------------------------------------------
*/
static bool
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index c3daacd..2dacdad 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -1870,6 +1870,7 @@ cost_append(AppendPath *apath)
foreach(l, apath->subpaths)
{
Path *subpath = (Path *) lfirst(l);
+ double subpath_parallel_divisor = get_parallel_divisor(subpath);
/*
* Append will start returning tuples when the child node having
@@ -1883,18 +1884,23 @@ cost_append(AppendPath *apath)
subpath->startup_cost);
/*
- * Apply parallel divisor to non-partial subpaths. Also add the
- * cost of partial paths to the total cost, but ignore non-partial
- * paths for now.
+ * Apply parallel divisor to subpaths. Scale the value of
+ * parallel divisor for partial paths as the number of rows
+ * computed for them might have used a different value for it.
+ * Also add the cost of partial paths to the total cost, but
+ * ignore non-partial paths for now.
*/
if (i < apath->first_partial_path)
apath->path.rows += subpath->rows / parallel_divisor;
else
{
- apath->path.rows += subpath->rows;
+ apath->path.rows += (subpath->rows * subpath_parallel_divisor /
+ parallel_divisor);
apath->path.total_cost += subpath->total_cost;
}
+ apath->path.rows = clamp_row_est(apath->path.rows);
+
i++;
}