summaryrefslogtreecommitdiff
path: root/src/backend/optimizer
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer')
-rw-r--r--src/backend/optimizer/plan/planmain.c2
-rw-r--r--src/backend/optimizer/plan/planner.c7
2 files changed, 6 insertions, 3 deletions
diff --git a/src/backend/optimizer/plan/planmain.c b/src/backend/optimizer/plan/planmain.c
index 16d3af32ed0..6647640b385 100644
--- a/src/backend/optimizer/plan/planmain.c
+++ b/src/backend/optimizer/plan/planmain.c
@@ -356,7 +356,7 @@ query_planner(PlannerInfo *root, List *tlist,
* can be divided by the number of tuples.
*/
if (tuple_fraction >= 1.0)
- tuple_fraction /= final_rel->rows;
+ tuple_fraction /= clamp_row_est(final_rel->rows);
}
/*
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 0bb8d20d8e6..300fbcec163 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -1295,11 +1295,14 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
/*
* Extract rowcount and width estimates for possible use in grouping
* decisions. Beware here of the possibility that
- * cheapest_path->parent is NULL (ie, there is no FROM clause).
+ * cheapest_path->parent is NULL (ie, there is no FROM clause). Also,
+ * if the final rel has been proven dummy, its rows estimate will be
+ * zero; clamp it to one to avoid zero-divide in subsequent
+ * calculations.
*/
if (cheapest_path->parent)
{
- path_rows = cheapest_path->parent->rows;
+ path_rows = clamp_row_est(cheapest_path->parent->rows);
path_width = cheapest_path->parent->width;
}
else