aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/planmain.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
commitea6e286491210e4ec2ddd542faccfe9227eb890f (patch)
tree2b001a99d52f08cb8bda84f817ee319cfed712fb /src/backend/optimizer/plan/planmain.c
parentd20327a4fdc13ca4a1ce25c91ceaf43927b6dc3c (diff)
downloadpostgresql-ea6e286491210e4ec2ddd542faccfe9227eb890f.tar.gz
postgresql-ea6e286491210e4ec2ddd542faccfe9227eb890f.zip
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/planmain.c')
-rw-r--r--src/backend/optimizer/plan/planmain.c2
1 files changed, 1 insertions, 1 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);
}
/*