Add commentary about Cygwin's broken erand48, per report from Andrew Dunstan.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 24 Jul 2009 15:03:07 +0000 (15:03 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 24 Jul 2009 15:03:07 +0000 (15:03 +0000)
configure
configure.in
src/backend/optimizer/geqo/geqo_selection.c

index 2ba6050bceb2b89909fb3d9afe67136affdf630f..fb41c024e21a04ecacc8332ef28f455a6a763eda 100755 (executable)
--- a/configure
+++ b/configure
@@ -19085,7 +19085,8 @@ esac
 
 fi
 
-# Cygwin's erand48 sometimes hangs, so force use of ours
+# Cygwin's erand48() is broken (always returns zero) in some releases,
+# so force use of ours.
 if test "$PORTNAME" = "cygwin"; then
   case " $LIBOBJS " in
   *" erand48.$ac_objext "* ) ;;
index ed6d52403842bb2405ab01a3abc812cf169d95e6..f1ee796d0fe0dac2f3ae8023fd778e6e1195004d 100644 (file)
@@ -1289,7 +1289,8 @@ if test "$PORTNAME" = "solaris"; then
   AC_LIBOBJ(getopt)
 fi
 
-# Cygwin's erand48 sometimes hangs, so force use of ours
+# Cygwin's erand48() is broken (always returns zero) in some releases,
+# so force use of ours.
 if test "$PORTNAME" = "cygwin"; then
   AC_LIBOBJ(erand48)
 fi
index 8a7e7dcda7c384bfd63f94079eb18f840ddc5561..f82487560ca8f4390d99031d00453c37306115de 100644 (file)
@@ -42,7 +42,7 @@
 #include "optimizer/geqo_random.h"
 #include "optimizer/geqo_selection.h"
 
-static int     linear(PlannerInfo *root, int max, double bias);
+static int     linear_rand(PlannerInfo *root, int max, double bias);
 
 
 /*
@@ -57,13 +57,21 @@ geqo_selection(PlannerInfo *root, Chromosome *momma, Chromosome *daddy,
        int                     first,
                                second;
 
-       first = linear(root, pool->size, bias);
-       second = linear(root, pool->size, bias);
+       first = linear_rand(root, pool->size, bias);
+       second = linear_rand(root, pool->size, bias);
 
+       /*
+        * Ensure we have selected different genes, except if pool size is only
+        * one, when we can't.
+        *
+        * This code has been observed to hang up in an infinite loop when the
+        * platform's implementation of erand48() is broken.  We consider that a
+        * feature: it lets you know you'd better fix the random-number generator.
+        */
        if (pool->size > 1)
        {
                while (first == second)
-                       second = linear(root, pool->size, bias);
+                       second = linear_rand(root, pool->size, bias);
        }
 
        geqo_copy(root, momma, &pool->data[first], pool->string_length);
@@ -71,7 +79,7 @@ geqo_selection(PlannerInfo *root, Chromosome *momma, Chromosome *daddy,
 }
 
 /*
- * linear
+ * linear_rand
  *       generates random integer between 0 and input max number
  *       using input linear bias
  *
@@ -81,7 +89,7 @@ geqo_selection(PlannerInfo *root, Chromosome *momma, Chromosome *daddy,
  *                      bias = (prob of first rule) / (prob of middle rule)
  */
 static int
-linear(PlannerInfo *root, int pool_size, double bias)
+linear_rand(PlannerInfo *root, int pool_size, double bias)
 {
        double          index;                  /* index between 0 and pop_size */
        double          max = (double) pool_size;