aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-12-26 23:38:42 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-12-26 23:38:42 +0000
commitf772e6cbf7f24245d59c4429f24a9c8cc4a9e38c (patch)
treeda03f9dcb146106dd654c2cf811d1a86b1257da8 /src
parent1dfbbd51e778c924b2958c69308adf02681d0801 (diff)
downloadpostgresql-f772e6cbf7f24245d59c4429f24a9c8cc4a9e38c.tar.gz
postgresql-f772e6cbf7f24245d59c4429f24a9c8cc4a9e38c.zip
Clamp the output of estimate_hash_bucketsize() to a sane range;
per example from Bruno Wolff in which it produced a silly result.
Diffstat (limited to 'src')
-rw-r--r--src/backend/optimizer/path/costsize.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index 5feaed49158..a19dd92c826 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -42,7 +42,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.96 2002/12/14 00:17:55 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.97 2002/12/26 23:38:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1164,6 +1164,16 @@ estimate_hash_bucketsize(Query *root, Var *var)
if (avgfreq > 0.0 && mcvfreq > avgfreq)
estfract *= mcvfreq / avgfreq;
+ /*
+ * Clamp bucketsize to sane range (the above adjustment could easily
+ * produce an out-of-range result). We set the lower bound a little
+ * above zero, since zero isn't a very sane result.
+ */
+ if (estfract < 1.0e-6)
+ estfract = 1.0e-6;
+ else if (estfract > 1.0)
+ estfract = 1.0;
+
ReleaseSysCache(tuple);
return (Selectivity) estfract;