]> granicus.if.org Git - postgresql/blobdiff - src/backend/optimizer/geqo/geqo_selection.c
Run pgindent on 9.2 source tree in preparation for first 9.3
[postgresql] / src / backend / optimizer / geqo / geqo_selection.c
index 0ba8941c22e05818bc5c36dc28f18299cf0f2aa3..fbdcc5ff0c997651052c5b2191236aa4e0c2eec3 100644 (file)
@@ -3,10 +3,10 @@
  * geqo_selection.c
  *       linear selection scheme for the genetic query optimizer
  *
- * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_selection.c,v 1.25 2009/07/16 20:55:44 tgl Exp $
+ * src/backend/optimizer/geqo/geqo_selection.c
  *
  *-------------------------------------------------------------------------
  */
@@ -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 was observed to hang up in an infinite loop when the
+        * platform's implementation of erand48() was broken.  We now always use
+        * our own version.
+        */
        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;