From 38dd3ae7d032eecc6ddadcbd402d90f6ac38f6a3 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Sat, 20 Jul 2002 04:59:10 +0000 Subject: [PATCH] The attached patch fixes a build problem with GEQO when using the 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 | 4 ++-- src/backend/optimizer/geqo/geqo_main.c | 39 ++++++++++++---------------------- src/backend/optimizer/geqo/geqo_misc.c | 7 ++++-- src/include/optimizer/geqo.h | 4 ++-- src/include/optimizer/geqo_misc.h | 9 ++++++-- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/backend/optimizer/geqo/Makefile b/src/backend/optimizer/geqo/Makefile index cc2c4bd667..973bfcf45e 100644 --- a/src/backend/optimizer/geqo/Makefile +++ b/src/backend/optimizer/geqo/Makefile @@ -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 diff --git a/src/backend/optimizer/geqo/geqo_main.c b/src/backend/optimizer/geqo/geqo_main.c index 198eb6167b..fda6d268a8 100644 --- a/src/backend/optimizer/geqo/geqo_main.c +++ b/src/backend/optimizer/geqo/geqo_main.c @@ -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); diff --git a/src/backend/optimizer/geqo/geqo_misc.c b/src/backend/optimizer/geqo/geqo_misc.c index 5385fc57fc..6ffc02b1c5 100644 --- a/src/backend/optimizer/geqo/geqo_misc.c +++ b/src/backend/optimizer/geqo/geqo_misc.c @@ -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 */ diff --git a/src/include/optimizer/geqo.h b/src/include/optimizer/geqo.h index 28fb662d20..04af4d7d88 100644 --- a/src/include/optimizer/geqo.h +++ b/src/include/optimizer/geqo.h @@ -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 */ /* diff --git a/src/include/optimizer/geqo_misc.h b/src/include/optimizer/geqo_misc.h index 79089835fa..eb35f6f3d9 100644 --- a/src/include/optimizer/geqo_misc.h +++ b/src/include/optimizer/geqo_misc.h @@ -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 $ * *------------------------------------------------------------------------- */ @@ -22,9 +22,12 @@ #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 */ -- 2.11.0