Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 672a807

Browse files
committed
Repair error apparently introduced in the initial coding of GUC: the
default value for geqo_effort is supposed to be 40, not 1. The actual 'genetic' component of the GEQO algorithm has been practically disabled since 7.1 because of this mistake. Improve documentation while at it.
1 parent 4d2e94e commit 672a807

File tree

5 files changed

+55
-38
lines changed

5 files changed

+55
-38
lines changed

doc/src/sgml/runtime.sgml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.230 2004/01/10 23:28:43 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.231 2004/01/21 23:33:34 tgl Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -1404,23 +1404,25 @@ SET ENABLE_SEQSCAN TO OFF;
14041404
</varlistentry>
14051405

14061406
<varlistentry>
1407-
<term><varname>geqo_effort</varname> (<type>integer</type>)</term>
1408-
<term><varname>geqo_generations</varname> (<type>integer</type>)</term>
14091407
<term><varname>geqo_pool_size</varname> (<type>integer</type>)</term>
1408+
<term><varname>geqo_generations</varname> (<type>integer</type>)</term>
1409+
<term><varname>geqo_effort</varname> (<type>integer</type>)</term>
14101410
<term><varname>geqo_selection_bias</varname> (<type>floating point</type>)</term>
14111411
<listitem>
14121412
<para>
14131413
Various tuning parameters for the genetic query optimization
1414-
algorithm: The pool size is the number of individuals in one
1414+
algorithm. The pool size is the number of individuals in one
14151415
population. Valid values are between 128 and 1024. If it is set
14161416
to 0 (the default) a pool size of 2^(QS+1), where QS is the
1417-
number of <literal>FROM</> items in the query, is taken. The effort is used
1418-
to calculate a default for generations. Valid values are between
1419-
1 and 80, 40 being the default. Generations specifies the number
1420-
of iterations in the algorithm. The number must be a positive
1421-
integer. If 0 is specified then <literal>Effort *
1422-
Log2(PoolSize)</literal> is used. The run time of the algorithm
1423-
is roughly proportional to the sum of pool size and generations.
1417+
number of <literal>FROM</> items in the query, is used.
1418+
Generations specifies the number of iterations of the algorithm.
1419+
The value must be a positive integer. If 0 is specified then
1420+
<literal>Effort * Log2(PoolSize)</literal> is used.
1421+
The run time of the algorithm is roughly proportional to the sum of
1422+
pool size and generations.
1423+
<varname>geqo_effort</varname> is only used in computing the default
1424+
generations setting, as just described. The default value is 40,
1425+
and the allowed range 1 to 100.
14241426
The selection bias is the selective pressure within the
14251427
population. Values can be from 1.50 to 2.00; the latter is the
14261428
default.

src/backend/optimizer/geqo/geqo_main.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_main.c,v 1.41 2003/11/29 19:51:50 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_main.c,v 1.42 2004/01/21 23:33:34 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -38,13 +38,13 @@
3838
* Configuration options
3939
*/
4040
int Geqo_pool_size;
41-
int Geqo_effort;
4241
int Geqo_generations;
42+
int Geqo_effort;
4343
double Geqo_selection_bias;
4444

4545

4646
static int gimme_pool_size(int nr_rel);
47-
static int gimme_number_generations(int pool_size, int effort);
47+
static int gimme_number_generations(int pool_size);
4848

4949
/* define edge recombination crossover [ERX] per default */
5050
#if !defined(ERX) && \
@@ -92,7 +92,7 @@ geqo(Query *root, int number_of_rels, List *initial_rels)
9292

9393
/* set GA parameters */
9494
pool_size = gimme_pool_size(number_of_rels);
95-
number_generations = gimme_number_generations(pool_size, Geqo_effort);
95+
number_generations = gimme_number_generations(pool_size);
9696
status_interval = 10;
9797

9898
/* allocate genetic pool memory */
@@ -284,7 +284,7 @@ gimme_pool_size(int nr_rel)
284284
{
285285
double size;
286286

287-
if (Geqo_pool_size != 0)
287+
if (Geqo_pool_size > 0)
288288
return Geqo_pool_size;
289289

290290
size = pow(2.0, nr_rel + 1.0);
@@ -305,10 +305,20 @@ gimme_pool_size(int nr_rel)
305305
* = Effort * Log2(PoolSize)
306306
*/
307307
static int
308-
gimme_number_generations(int pool_size, int effort)
308+
gimme_number_generations(int pool_size)
309309
{
310-
if (Geqo_generations <= 0)
311-
return effort * (int) ceil(log((double) pool_size) / log(2.0));
312-
else
310+
double gens;
311+
312+
if (Geqo_generations > 0)
313313
return Geqo_generations;
314+
315+
gens = Geqo_effort * log((double) pool_size) / log(2.0);
316+
317+
/* bound it to a sane range */
318+
if (gens <= 0)
319+
gens = 1;
320+
else if (gens > 10000)
321+
gens = 10000;
322+
323+
return (int) ceil(gens);
314324
}

src/backend/utils/misc/guc.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.177 2004/01/19 19:04:40 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.178 2004/01/21 23:33:34 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -931,23 +931,23 @@ static struct config_int ConfigureNamesInt[] =
931931
&Geqo_pool_size,
932932
DEFAULT_GEQO_POOL_SIZE, 0, MAX_GEQO_POOL_SIZE, NULL, NULL
933933
},
934-
{
935-
{"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
936-
gettext_noop("GEQO: effort is used to calculate a default for generations."),
937-
NULL
938-
},
939-
&Geqo_effort,
940-
1, 1, INT_MAX, NULL, NULL
941-
},
942934
{
943935
{"geqo_generations", PGC_USERSET, QUERY_TUNING_GEQO,
944-
gettext_noop("GEQO: number of iterations in the algorithm."),
945-
gettext_noop("The number must be a positive integer. If 0 is "
936+
gettext_noop("GEQO: number of iterations of the algorithm."),
937+
gettext_noop("The value must be a positive integer. If 0 is "
946938
"specified then effort * log2(poolsize) is used.")
947939
},
948940
&Geqo_generations,
949941
0, 0, INT_MAX, NULL, NULL
950942
},
943+
{
944+
{"geqo_effort", PGC_USERSET, QUERY_TUNING_GEQO,
945+
gettext_noop("GEQO: effort is used to set the default for generations."),
946+
NULL
947+
},
948+
&Geqo_effort,
949+
DEFAULT_GEQO_EFFORT, MIN_GEQO_EFFORT, MAX_GEQO_EFFORT, NULL, NULL
950+
},
951951

952952
{
953953
{"deadlock_timeout", PGC_SIGHUP, LOCK_MANAGEMENT,

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@
123123

124124
#geqo = true
125125
#geqo_threshold = 11
126-
#geqo_effort = 1
127-
#geqo_generations = 0
128126
#geqo_pool_size = 0 # default based on tables in statement,
129127
# range 128-1024
128+
#geqo_generations = 0 # use default: effort * log2(pool_size)
129+
#geqo_effort = 40 # range 1-100
130130
#geqo_selection_bias = 2.0 # range 1.5-2.0
131131

132132
# - Other Planner Options -

src/include/optimizer/geqo.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/optimizer/geqo.h,v 1.33 2003/11/29 22:41:07 pgsql Exp $
9+
* $PostgreSQL: pgsql/src/include/optimizer/geqo.h,v 1.34 2004/01/21 23:33:34 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -44,22 +44,27 @@
4444

4545
/*
4646
* Configuration options
47+
*
48+
* If you change these, update backend/utils/misc/postgresql.sample.conf
4749
*/
48-
/* If you change these, update backend/utils/misc/postgresql.sample.conf */
4950
extern int Geqo_pool_size;
5051

5152
#define DEFAULT_GEQO_POOL_SIZE 0 /* = default based on no. of relations. */
5253
#define MIN_GEQO_POOL_SIZE 128
5354
#define MAX_GEQO_POOL_SIZE 1024
5455

55-
extern int Geqo_effort; /* 1 .. inf, only used to calculate
56-
* generations default */
5756
extern int Geqo_generations; /* 1 .. inf, or 0 to use default based on
5857
* pool size */
5958

59+
extern int Geqo_effort; /* only used to calculate default for
60+
* generations */
61+
62+
#define DEFAULT_GEQO_EFFORT 40
63+
#define MIN_GEQO_EFFORT 1
64+
#define MAX_GEQO_EFFORT 100
65+
6066
extern double Geqo_selection_bias;
6167

62-
/* If you change these, update backend/utils/misc/postgresql.sample.conf */
6368
#define DEFAULT_GEQO_SELECTION_BIAS 2.0
6469
#define MIN_GEQO_SELECTION_BIAS 1.5
6570
#define MAX_GEQO_SELECTION_BIAS 2.0

0 commit comments

Comments
 (0)