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 009841d9dd3..e2967d1cf61 100644
--- a/src/backend/optimizer/plan/planmain.c
+++ b/src/backend/optimizer/plan/planmain.c
@@ -365,7 +365,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 3a812877d62..e062cabf7a2 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -1134,11 +1134,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