postgres.git / summary / log / commit / refs
commit fa09f8935156533584b4e215bdf70ec1ff968dad
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Sun Mar 27 22:06:53 2016 +0000
Clamp adjusted ndistinct to positive integer in estimate_hash_bucketsize().
This avoids a possible divide-by-zero in the following calculation,
and rounding the number to an integer seems like saner behavior anyway.
Assuming IEEE math, the division would yield +Infinity which would get
replaced by 1.0 at the bottom of the function, so nothing really
interesting would ensue; but avoiding divide-by-zero seems like a
good idea on general principles.
Per report from Piotr Stefaniak. No back-patch since this seems
mostly cosmetic.
src/backend/utils/adt/selfuncs.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index b2c57e87a5e..30751fc8ac6 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -3541,7 +3541,10 @@ estimate_hash_bucketsize(PlannerInfo *root, Node *hashkey, double nbuckets)
* selectivity of rel's restriction clauses that mention the target Var.
*/
if (vardata.rel)
+ {
ndistinct *= vardata.rel->rows / vardata.rel->tuples;
+ ndistinct = clamp_row_est(ndistinct);
+ }
/*
* Initial estimate of bucketsize fraction is 1/nbuckets as long as the
[parent: 408f0438531e]