summaryrefslogtreecommitdiff
path: root/src/include/optimizer
diff options
context:
space:
mode:
authorTom Lane2004-01-23 23:54:21 +0000
committerTom Lane2004-01-23 23:54:21 +0000
commit3969f2924bead7847adbe1fd736eefaf138af942 (patch)
tree81bf0fa12a7c80a15b4a94e051b1e576aa3c7b4f /src/include/optimizer
parent81c554bbe8303d0c554430cbcd4a7804d85ddd24 (diff)
Revise GEQO planner to make use of some heuristic knowledge about SQL, namely
that it's good to join where there are join clauses rather than where there are not. Also enable it to generate bushy plans at need, so that it doesn't fail in the presence of multiple IN clauses containing sub-joins. These changes appear to improve the behavior enough that we can substantially reduce the default pool size and generations count, thereby decreasing the runtime, and yet get as good or better plans as we were getting in 7.4. Consequently, adjust the default GEQO parameters. I also modified the way geqo_effort is used so that it affects both population size and number of generations; it's now useful as a single control to adjust the GEQO runtime-vs-plan-quality tradeoff. Bump geqo_threshold to 12, since even with these changes GEQO seems to be slower than the regular planner at 11 relations.
Diffstat (limited to 'src/include/optimizer')
-rw-r--r--src/include/optimizer/geqo.h39
-rw-r--r--src/include/optimizer/geqo_pool.h9
2 files changed, 26 insertions, 22 deletions
diff --git a/src/include/optimizer/geqo.h b/src/include/optimizer/geqo.h
index caa05f52ee9..e9bfdfcff66 100644
--- a/src/include/optimizer/geqo.h
+++ b/src/include/optimizer/geqo.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/optimizer/geqo.h,v 1.34 2004/01/21 23:33:34 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/optimizer/geqo.h,v 1.35 2004/01/23 23:54:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -25,6 +25,7 @@
#include "nodes/relation.h"
#include "optimizer/geqo_gene.h"
+
/* GEQO debug flag */
/*
#define GEQO_DEBUG
@@ -47,21 +48,15 @@
*
* If you change these, update backend/utils/misc/postgresql.sample.conf
*/
-extern int Geqo_pool_size;
-
-#define DEFAULT_GEQO_POOL_SIZE 0 /* = default based on no. of relations. */
-#define MIN_GEQO_POOL_SIZE 128
-#define MAX_GEQO_POOL_SIZE 1024
+extern int Geqo_effort; /* 1 .. 10, knob for adjustment of defaults */
-extern int Geqo_generations; /* 1 .. inf, or 0 to use default based on
- * pool size */
+#define DEFAULT_GEQO_EFFORT 5
+#define MIN_GEQO_EFFORT 1
+#define MAX_GEQO_EFFORT 10
-extern int Geqo_effort; /* only used to calculate default for
- * generations */
+extern int Geqo_pool_size; /* 2 .. inf, or 0 to use default */
-#define DEFAULT_GEQO_EFFORT 40
-#define MIN_GEQO_EFFORT 1
-#define MAX_GEQO_EFFORT 100
+extern int Geqo_generations; /* 1 .. inf, or 0 to use default */
extern double Geqo_selection_bias;
@@ -70,13 +65,23 @@ extern double Geqo_selection_bias;
#define MAX_GEQO_SELECTION_BIAS 2.0
+/*
+ * Data structure to encapsulate information needed for building plan trees
+ * (i.e., geqo_eval and gimme_tree).
+ */
+typedef struct
+{
+ Query *root; /* the query we are planning */
+ List *initial_rels; /* the base relations */
+} GeqoEvalData;
+
+
/* routines in geqo_main.c */
extern RelOptInfo *geqo(Query *root, int number_of_rels, List *initial_rels);
/* routines in geqo_eval.c */
-extern Cost geqo_eval(Query *root, List *initial_rels,
- Gene *tour, int num_gene);
-extern RelOptInfo *gimme_tree(Query *root, List *initial_rels,
- Gene *tour, int num_gene);
+extern Cost geqo_eval(Gene *tour, int num_gene, GeqoEvalData *evaldata);
+extern RelOptInfo *gimme_tree(Gene *tour, int num_gene,
+ GeqoEvalData *evaldata);
#endif /* GEQO_H */
diff --git a/src/include/optimizer/geqo_pool.h b/src/include/optimizer/geqo_pool.h
index 4028b2c104d..a4f40c98897 100644
--- a/src/include/optimizer/geqo_pool.h
+++ b/src/include/optimizer/geqo_pool.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/optimizer/geqo_pool.h,v 1.18 2003/11/29 22:41:07 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/optimizer/geqo_pool.h,v 1.19 2004/01/23 23:54:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -23,14 +23,13 @@
#ifndef GEQO_POOL_H
#define GEQO_POOL_H
-#include "optimizer/geqo_gene.h"
-#include "nodes/parsenodes.h"
+#include "optimizer/geqo.h"
+
extern Pool *alloc_pool(int pool_size, int string_length);
extern void free_pool(Pool *pool);
-extern void random_init_pool(Query *root, List *initial_rels,
- Pool *pool, int strt, int stop);
+extern void random_init_pool(Pool *pool, GeqoEvalData *evaldata);
extern Chromosome *alloc_chromo(int string_length);
extern void free_chromo(Chromosome *chromo);