]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
The attached patch fixes a build problem with GEQO when using the
authorBruce Momjian <bruce@momjian.us>
Sat, 20 Jul 2002 04:59:10 +0000 (04:59 +0000)
committerBruce Momjian <bruce@momjian.us>
Sat, 20 Jul 2002 04:59:10 +0000 (04:59 +0000)
PX recombination operator, changes some elog() messages from LOG
to DEBUG1, puts some debugging functions inside the appropriate
#ifdef (not enabled by default), and makes a few other minor
cleanups.

BTW, the elog() change is motivated by at least one user who
has sent a concerned email to -general asking exactly what the
"ERX recombination operator" is, and what it is doing to their
DBMS.

Neil Conway

src/backend/optimizer/geqo/Makefile
src/backend/optimizer/geqo/geqo_main.c
src/backend/optimizer/geqo/geqo_misc.c
src/include/optimizer/geqo.h
src/include/optimizer/geqo_misc.h

index cc2c4bd667da0bf6b382dd26d779466056d4db85..973bfcf45e347c262e1b17413de0ca2b1228b765 100644 (file)
@@ -5,7 +5,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/backend/optimizer/geqo/Makefile,v 1.16 2000/08/31 16:10:08 petere Exp $
+# $Header: /cvsroot/pgsql/src/backend/optimizer/geqo/Makefile,v 1.17 2002/07/20 04:59:10 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -14,7 +14,7 @@ top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
 OBJS = geqo_copy.o geqo_eval.o geqo_main.o geqo_misc.o \
-       geqo_pool.o geqo_recombination.o \
+       geqo_mutation.o geqo_pool.o geqo_recombination.o \
        geqo_selection.o \
        geqo_erx.o geqo_pmx.o geqo_cx.o geqo_px.o geqo_ox1.o geqo_ox2.o
 
index 198eb6167b835e0674ef9e4daa6c924fe8a84509..fda6d268a8e55dde224c19cdfcf40aeda3b7a664 100644 (file)
@@ -1,13 +1,13 @@
 /*------------------------------------------------------------------------
  *
  * geqo_main.c
- *       solution of the query optimization problem
+ *       solution to the query optimization problem
  *       by means of a Genetic Algorithm (GA)
  *
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: geqo_main.c,v 1.31 2002/06/20 20:29:29 momjian Exp $
+ * $Id: geqo_main.c,v 1.32 2002/07/20 04:59:10 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -29,6 +29,7 @@
 
 #include "optimizer/geqo.h"
 #include "optimizer/geqo_misc.h"
+#include "optimizer/geqo_mutation.h"
 #include "optimizer/geqo_pool.h"
 #include "optimizer/geqo_selection.h"
 
@@ -46,7 +47,6 @@ int                   Geqo_random_seed;
 static int     gimme_pool_size(int nr_rel);
 static int     gimme_number_generations(int pool_size, int effort);
 
-
 /* define edge recombination crossover [ERX] per default */
 #if !defined(ERX) && \
        !defined(PMX) && \
@@ -120,30 +120,30 @@ geqo(Query *root, int number_of_rels, List *initial_rels)
        daddy = alloc_chromo(pool->string_length);
 
 #if defined (ERX)
-       elog(LOG, "geqo_main: using edge recombination crossover [ERX]");
+       elog(DEBUG1, "geqo_main: using edge recombination crossover [ERX]");
 /* allocate edge table memory */
        edge_table = alloc_edge_table(pool->string_length);
 #elif defined(PMX)
-       elog(LOG, "geqo_main: using partially matched crossover [PMX]");
+       elog(DEBUG1, "geqo_main: using partially matched crossover [PMX]");
 /* allocate chromosome kid memory */
        kid = alloc_chromo(pool->string_length);
 #elif defined(CX)
-       elog(LOG, "geqo_main: using cycle crossover [CX]");
+       elog(DEBUG1, "geqo_main: using cycle crossover [CX]");
 /* allocate city table memory */
        kid = alloc_chromo(pool->string_length);
        city_table = alloc_city_table(pool->string_length);
 #elif defined(PX)
-       elog(LOG, "geqo_main: using position crossover [PX]");
+       elog(DEBUG1, "geqo_main: using position crossover [PX]");
 /* allocate city table memory */
        kid = alloc_chromo(pool->string_length);
        city_table = alloc_city_table(pool->string_length);
 #elif defined(OX1)
-       elog(LOG, "geqo_main: using order crossover [OX1]");
+       elog(DEBUG1, "geqo_main: using order crossover [OX1]");
 /* allocate city table memory */
        kid = alloc_chromo(pool->string_length);
        city_table = alloc_city_table(pool->string_length);
 #elif defined(OX2)
-       elog(LOG, "geqo_main: using order crossover [OX2]");
+       elog(DEBUG1, "geqo_main: using order crossover [OX2]");
 /* allocate city table memory */
        kid = alloc_chromo(pool->string_length);
        city_table = alloc_city_table(pool->string_length);
@@ -155,19 +155,13 @@ geqo(Query *root, int number_of_rels, List *initial_rels)
 
        for (generation = 0; generation < number_generations; generation++)
        {
-
-               /* SELECTION */
-               geqo_selection(momma, daddy, pool, Geqo_selection_bias);                /* using linear bias
-                                                                                                                                                * function */
-
-
+               /* SELECTION: using linear bias function */
+               geqo_selection(momma, daddy, pool, Geqo_selection_bias);
 
 #if defined (ERX)
                /* EDGE RECOMBINATION CROSSOVER */
                difference = gimme_edge_table(momma->string, daddy->string, pool->string_length, edge_table);
 
-               /* let the kid grow in momma's womb (storage) for nine months ;-) */
-               /* sleep(23328000) -- har har har */
                kid = momma;
 
                /* are there any edge failures ? */
@@ -209,7 +203,7 @@ geqo(Query *root, int number_of_rels, List *initial_rels)
                        print_gen(stdout, pool, generation);
 #endif
 
-       }                                                       /* end of iterative optimization */
+       }
 
 
 #if defined(ERX) && defined(GEQO_DEBUG)
@@ -289,14 +283,7 @@ gimme_pool_size(int nr_rel)
        double          size;
 
        if (Geqo_pool_size != 0)
-       {
-               if (Geqo_pool_size < MIN_GEQO_POOL_SIZE)
-                       return MIN_GEQO_POOL_SIZE;
-               else if (Geqo_pool_size > MAX_GEQO_POOL_SIZE)
-                       return MAX_GEQO_POOL_SIZE;
-               else
-                       return Geqo_pool_size;
-       }
+               return Geqo_pool_size;
 
        size = pow(2.0, nr_rel + 1.0);
 
index 5385fc57fc78613bcacab96c19216f6444d36bda..6ffc02b1c5be414aa109fd192daa1dc2c7694598 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: geqo_misc.c,v 1.32 2002/06/20 20:29:29 momjian Exp $
+ * $Id: geqo_misc.c,v 1.33 2002/07/20 04:59:10 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -26,6 +26,7 @@
 #include "optimizer/geqo_misc.h"
 #include "nodes/print.h"
 
+#ifdef GEQO_DEBUG
 
 static float avg_pool(Pool *pool);
 
@@ -92,7 +93,7 @@ print_gen(FILE *fp, Pool *pool, int generation)
        lowest = pool->size > 1 ? pool->size - 2 : 0;
 
        fprintf(fp,
-                       "%5d | Bst: %f  Wst: %f  Mean: %f  Avg: %f\n",
+                       "%5d | Best: %f  Worst: %f  Mean: %f  Avg: %f\n",
                        generation,
                        pool->data[0].worth,
                        pool->data[lowest].worth,
@@ -248,3 +249,5 @@ geqo_print_rel(Query *root, RelOptInfo *rel)
        printf("\n\tcheapest total path:\n");
        geqo_print_path(root, rel->cheapest_total_path, 1);
 }
+
+#endif /* GEQO_DEBUG */
index 28fb662d2074f89280a885a835f0d126f824d21a..04af4d7d88cc723f7388f80c0133e9cb560ad20e 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: geqo.h,v 1.28 2002/06/20 20:29:51 momjian Exp $
+ * $Id: geqo.h,v 1.29 2002/07/20 04:59:10 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -28,7 +28,7 @@
 /* GEQO debug flag */
 /*
  #define GEQO_DEBUG
-*/
+ */
 
 /* recombination mechanism */
 /*
index 79089835fa92ed7f078de4d7f093463879d061d3..eb35f6f3d96b17b108d142c29ed30ebd6a4a9b0a 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: geqo_misc.h,v 1.19 2002/06/20 20:29:51 momjian Exp $
+ * $Id: geqo_misc.h,v 1.20 2002/07/20 04:59:10 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
 #ifndef GEQO_MISC_H
 #define GEQO_MISC_H
 
+#include "optimizer/geqo.h"
 #include "optimizer/geqo_recombination.h"
 #include "nodes/relation.h"
 
+#ifdef GEQO_DEBUG
+
 extern void print_pool(FILE *fp, Pool *pool, int start, int stop);
 extern void print_gen(FILE *fp, Pool *pool, int generation);
 extern void print_edge_table(FILE *fp, Edge *edge_table, int num_gene);
@@ -33,4 +36,6 @@ extern void geqo_print_rel(Query *root, RelOptInfo *rel);
 extern void geqo_print_path(Query *root, Path *path, int indent);
 extern void geqo_print_joinclauses(Query *root, List *clauses);
 
-#endif   /* GEQO_MISC_H */
+#endif /* GEQO_DEBUG */
+
+#endif /* GEQO_MISC_H */