summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/planner.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2015-07-30 12:11:23 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2015-07-30 12:11:23 -0400
commite91a1643ac723477d6ec2d47c8486cd0013660bb (patch)
treea8f0f8db85f184c3357f6d6cafb0df28a2710e0b /src/backend/optimizer/plan/planner.c
parent2e75be6660dbaaf2da09b98c54d47c9fe0ac8cfa (diff)
Avoid some zero-divide hazards in the planner.
Although I think on all modern machines floating division by zero results in Infinity not SIGFPE, we still don't want infinities running around in the planner's costing estimates; too much risk of that leading to insane behavior. grouping_planner() failed to consider the possibility that final_rel might be known dummy and hence have zero rowcount. (I wonder if it would be better to set a rows estimate of 1 for dummy relations? But at least in the back branches, changing this convention seems like a bad idea, so I'll leave that for another day.) Make certain that get_variable_numdistinct() produces a nonzero result. The case that can be shown to be broken is with stadistinct < 0.0 and small ntuples; we did not prevent the result from rounding to zero. For good luck I applied clamp_row_est() to all the nonconstant return values. In ExecChooseHashTableSize(), Assert that we compute positive nbuckets and nbatch. I know of no reason to think this isn't the case, but it seems like a good safety check. Per reports from Piotr Stefaniak. Back-patch to all active branches.
Diffstat (limited to 'src/backend/optimizer/plan/planner.c')
-rw-r--r--src/backend/optimizer/plan/planner.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 6ee411eec87..09d4ea12e87 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -1536,9 +1536,11 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
standard_qp_callback, &qp_extra);
/*
- * Extract rowcount and width estimates for use below.
+ * Extract rowcount and width estimates for use below. If final_rel
+ * has been proven dummy, its rows estimate will be zero; clamp it to
+ * one to avoid zero-divide in subsequent calculations.
*/
- path_rows = final_rel->rows;
+ path_rows = clamp_row_est(final_rel->rows);
path_width = final_rel->width;
/*