1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Merge in GEQO Optimizer

From: "Martin S. Utesch" <utesch@aut.tu-freiberg.de>
This commit is contained in:
Marc G. Fournier
1997-02-19 12:59:07 +00:00
parent 34f35a4c19
commit 29138eeb3c
29 changed files with 3823 additions and 3 deletions

View File

@@ -256,6 +256,18 @@
/* #define OLD_REWRITE */
/* #define NOTYET */
/* Genetic Query Optimization (GEQO):
*
* The GEQO module in PostgreSQL is intended for the solution of the
* query optimization problem by means of a Genetic Algorithm (GA).
* It allows the handling of large JOIN queries through non-exhaustive
* search.
* For further information see README.GEQO <utesch@aut.tu-freiberg.de>.
*/
#define GEQO /* backend/optimizer/path/allpaths.c */
/* Undocumented "features"? */
#define FASTBUILD /* access/nbtree/nbtsort.c */

View File

@@ -0,0 +1,78 @@
/*-------------------------------------------------------------------------
*
* geqo.h--
* prototypes for various files in optimizer/geqo
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: geqo.h,v 1.1 1997/02/19 12:58:28 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
/* contributed by:
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
* Martin Utesch * Institute of Automatic Control *
= = University of Mining and Technology =
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
*/
#ifndef GEQO_H
#define GEQO_H
/* GEQO debug flag */
/*
#define GEQO_DEBUG
*/
/* recombination mechanism */
/*
#define ERX
#define PMX
#define CX
#define PX
#define OX1
#define OX2
*/
#define ERX
/* genetic algorithm parameters */
#define GEQO_FILE "pg_geqo" /* Name of the ga config file */
#define MIN_POOL 128 /* minimum number of individuals */
#define MAX_POOL 1024 /* maximum number of individuals */
#define LOW_EFFORT 1 /* optimization effort values */
#define MEDIUM_EFFORT 40 /* are multipliers for computed */
#define HIGH_EFFORT 80 /* number of generations */
#define SELECTION_BIAS 2.0 /* selective pressure within population */
/* should be 1.5 <= SELECTION_BIAS <= 2.0 */
int PoolSize;
int Generations;
long RandomSeed; /* defaults to (long) time(NULL) in geqo_params.c */
double SelectionBias;
/* logarithmic base for rel->size decrease in case of long
queries that cause an integer overflow; used in geqo_eval.c */
#define GEQO_LOG_BASE 1.5 /* should be 1.0 < GEQO_LOG_BASE <= 2.0 */
/* ^^^ */
/* geqo prototypes */
extern Rel *geqo(Query *root);
extern void geqo_params(int string_length);
extern Cost geqo_eval (Query *root, Gene *tour, int num_gene);
double geqo_log(double x, double b);
extern Rel *gimme_tree(Query *root, Gene *tour, int rel_count, int num_gene, Rel *outer_rel);
#endif /* GEQO_H */

View File

@@ -0,0 +1,27 @@
/*-------------------------------------------------------------------------
*
* geqo_copy.h--
* prototypes for copy functions in optimizer/geqo
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: geqo_copy.h,v 1.1 1997/02/19 12:58:32 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
/* contributed by:
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
* Martin Utesch * Institute of Automatic Control *
= = University of Mining and Technology =
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
*/
#ifndef GEQO_COPY_H
#define GEQO_COPY_H
extern void geqo_copy (Chromosome *chromo1, Chromosome *chromo2, int string_length);
#endif /* GEQO_COPY_H */

View File

@@ -0,0 +1,42 @@
/*-------------------------------------------------------------------------
*
* geqo_gene.h--
* genome representation in optimizer/geqo
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: geqo_gene.h,v 1.1 1997/02/19 12:58:37 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
/* contributed by:
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
* Martin Utesch * Institute of Automatic Control *
= = University of Mining and Technology =
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
*/
#ifndef GEQO_GENE_H
#define GEQO_GENE_H
/* we presume that int instead of Relid
is o.k. for Gene; so don't change it! */
typedef
int Gene;
typedef struct Chromosome {
Gene *string;
Cost worth;
} Chromosome;
typedef struct Pool {
Chromosome *data;
int size;
int string_length;
} Pool;
#endif /* GEQO_GENE_H */

View File

@@ -0,0 +1,34 @@
/*-------------------------------------------------------------------------
*
* geqo_misc.h--
* prototypes for printout routines in optimizer/geqo
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: geqo_misc.h,v 1.1 1997/02/19 12:58:41 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
/* contributed by:
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
* Martin Utesch * Institute of Automatic Control *
= = University of Mining and Technology =
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
*/
#ifndef GEQO_MISC_H
#define GEQO_MISC_H
#include <stdio.h>
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);
extern void geqo_print_rel(Query *root, Rel *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 */

View File

@@ -0,0 +1,27 @@
/*-------------------------------------------------------------------------
*
* geqo_mutation.h--
* prototypes for mutation functions in optimizer/geqo
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: geqo_mutation.h,v 1.1 1997/02/19 12:58:49 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
/* contributed by:
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
* Martin Utesch * Institute of Automatic Control *
= = University of Mining and Technology =
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
*/
#ifndef GEQO_MUTATION_H
#define GEQO_MUTATION_H
extern void geqo_mutation (Gene *tour, int num_gene);
#endif /* GEQO_MUTATION_H */

View File

@@ -0,0 +1,28 @@
/*-------------------------------------------------------------------------
*
* geqo_paths.h--
* prototypes for various subroutines in geqo_path.c
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: geqo_paths.h,v 1.1 1997/02/19 12:58:55 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
/* contributed by:
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
* Martin Utesch * Institute of Automatic Control *
= = University of Mining and Technology =
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
*/
#ifndef GEQO_PATHS_H
#define GEQO_PATHS_H
extern List *geqo_prune_rels(List *rel_list);
extern void geqo_rel_paths(Rel *rel);
#endif /* GEQO_PATHS_H */

View File

@@ -0,0 +1,37 @@
/*-------------------------------------------------------------------------
*
* geqo_pool.h--
* pool representation in optimizer/geqo
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: geqo_pool.h,v 1.1 1997/02/19 12:58:59 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
/* contributed by:
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
* Martin Utesch * Institute of Automatic Control *
= = University of Mining and Technology =
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
*/
#ifndef GEQO_POOL_H
#define GEQO_POOL_H
extern Pool *alloc_pool(int pool_size, int string_length);
extern void free_pool(Pool *pool);
extern void random_init_pool(Query *root, Pool *pool, int strt, int stop);
extern Chromosome *alloc_chromo(int string_length);
extern void free_chromo(Chromosome *chromo);
extern void spread_chromo(Chromosome *chromo, Pool *pool);
extern void sort_pool (Pool *pool);
#endif /* GEQO_POOL_H */

View File

@@ -0,0 +1,37 @@
/*-------------------------------------------------------------------------
*
* geqo_random.h--
* random number generator
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: geqo_random.h,v 1.1 1997/02/19 12:59:02 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
/* contributed by:
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
* Martin Utesch * Institute of Automatic Control *
= = University of Mining and Technology =
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
*/
/* -- parts of this are adapted from D. Whitley's Genitor algorithm -- */
#ifndef GEQO_RANDOM_H
#define GEQO_RANDOM_H
#include <math.h>
#define MASK 2147483647
#define geqo_rand() ((double)random()/MASK)
/* geqo_randint returns integer value
between lower and upper inclusive */
#define geqo_randint(upper,lower) ( (int) floor( geqo_rand()*((upper-lower)+0.999999) ) + lower )
#endif /* GEQO_RANDOM_H */

View File

@@ -0,0 +1,77 @@
/*-------------------------------------------------------------------------
*
* geqo_recombination.h--
* prototypes for recombination in the genetic query optimizer
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: geqo_recombination.h,v 1.1 1997/02/19 12:59:04 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
/* contributed by:
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
* Martin Utesch * Institute of Automatic Control *
= = University of Mining and Technology =
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
*/
/* -- parts of this are adapted from D. Whitley's Genitor algorithm -- */
#ifndef GEQO_RECOMBINATION_H
#define GEQO_RECOMBINATION_H
extern void init_tour(Gene *tour, int num_gene);
/* edge recombination crossover [ERX] */
typedef struct Edge {
Gene edge_list[4]; /* list of edges */
int total_edges;
int unused_edges;
} Edge;
extern Edge *alloc_edge_table(int num_gene);
extern void free_edge_table(Edge *edge_table);
extern float gimme_edge_table (Gene *tour1, Gene *tour2, int num_gene, Edge *edge_table);
extern int gimme_tour(Edge *edge_table, Gene *new_gene, int num_gene);
/* partially matched crossover [PMX] */
#define DAD 1 /* indicator for gene from dad */
#define MOM 0 /* indicator for gene from mom */
extern void pmx(Gene *tour1, Gene *tour2, Gene *offspring, int num_gene);
typedef struct City {
int tour2_position;
int tour1_position;
int used;
int select_list;
} City;
extern City *alloc_city_table(int num_gene);
extern void free_city_table(City *city_table);
/* cycle crossover [CX] */
extern int cx(Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table);
/* position crossover [PX] */
extern void px(Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table);
/* order crossover [OX1] according to Davis */
extern void ox1(Gene *mom, Gene *dad, Gene *offspring, int num_gene, City *city_table);
/* order crossover [OX2] according to Syswerda */
extern void ox2(Gene *mom, Gene *dad, Gene *offspring, int num_gene, City *city_table);
#endif /* GEQO_RECOMBINATION_H */

View File

@@ -0,0 +1,28 @@
/*-------------------------------------------------------------------------
*
* geqo_selection.h--
* prototypes for selection routines in optimizer/geqo
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: geqo_selection.h,v 1.1 1997/02/19 12:59:07 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
/* contributed by:
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
* Martin Utesch * Institute of Automatic Control *
= = University of Mining and Technology =
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
*/
#ifndef GEQO_SELECTION_H
#define GEQO_SELECTION_H
extern void geqo_selection (Chromosome *momma, Chromosome *daddy, Pool *pool, double bias);
#endif /* GEQO_SELECTION_H */