Skip to content

Commit f1b7823

Browse files
committed
Make GEQO use dependent on table and index count.
1 parent eb34155 commit f1b7823

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

doc/src/sgml/ref/set.sgml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ SET TIME ZONE { '<REPLACEABLE CLASS="PARAMETER">timezone</REPLACEABLE>' | LOCAL
406406
</para>
407407
<para>
408408
This algorithm is on by default, which used GEQO for
409-
statements of six or more tables.
409+
statements of six or more tables and indexes.
410410
(See the chapter on GEQO in the Programmer's Guide
411411
for more information).
412412
</para>
@@ -676,6 +676,11 @@ SET TIME ZONE { '<REPLACEABLE CLASS="PARAMETER">timezone</REPLACEABLE>' | LOCAL
676676
--
677677
SET DATESTYLE TO 'ISO';
678678
</programlisting>
679+
<programlisting>
680+
--Enable GEQO for queries with 4 or more tables and indexes
681+
--
682+
SET GEQO ON=4;
683+
</programlisting>
679684
<programlisting>
680685
--Set GEQO to default:
681686
--

src/backend/optimizer/path/allpaths.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/allpaths.c,v 1.23 1998/09/01 04:29:27 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/allpaths.c,v 1.24 1999/02/02 20:30:05 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -78,15 +78,13 @@ find_paths(Query *root, List *rels)
7878

7979
if (levels_needed <= 1)
8080
{
81-
8281
/*
8382
* Unsorted single relation, no more processing is required.
8483
*/
8584
return rels;
8685
}
8786
else
8887
{
89-
9088
/*
9189
* this means that joins or sorts are required. set selectivities
9290
* of clauses that have not been set by an index.
@@ -123,7 +121,7 @@ find_rel_paths(Query *root, List *rels)
123121

124122
rel_index_scan_list = find_index_paths(root,
125123
rel,
126-
find_relation_indices(root, rel),
124+
find_relation_indices(root, rel),
127125
rel->clauseinfo,
128126
rel->joininfo);
129127

@@ -182,18 +180,27 @@ find_join_paths(Query *root, List *outer_rels, int levels_needed)
182180
* genetic query optimizer entry point *
183181
* <utesch@aut.tu-freiberg.de> *
184182
*******************************************/
183+
{
184+
List *temp;
185+
int paths_to_consider = 0;
185186

186-
if ((_use_geqo_) && length(root->base_rel_list) >= _use_geqo_rels_)
187-
return lcons(geqo(root), NIL); /* returns *one* RelOptInfo, so
188-
* lcons it */
187+
foreach(temp, outer_rels)
188+
{
189+
RelOptInfo *rel = (RelOptInfo *) lfirst(temp);
190+
paths_to_consider += length(rel->pathlist);
191+
}
189192

193+
if ((_use_geqo_) && paths_to_consider >= _use_geqo_rels_)
194+
/* returns _one_ RelOptInfo, so lcons it */
195+
return lcons(geqo(root), NIL);
196+
}
197+
190198
/*******************************************
191199
* rest will be deprecated in case of GEQO *
192200
*******************************************/
193201

194202
while (--levels_needed)
195203
{
196-
197204
/*
198205
* Determine all possible pairs of relations to be joined at this
199206
* level. Determine paths for joining these relation pairs and
@@ -207,7 +214,6 @@ find_join_paths(Query *root, List *outer_rels, int levels_needed)
207214
prune_joinrels(new_rels);
208215

209216
#if 0
210-
211217
/*
212218
* * for each expensive predicate in each path in each distinct
213219
* rel, * consider doing pullup -- JMH
@@ -247,7 +253,6 @@ find_join_paths(Query *root, List *outer_rels, int levels_needed)
247253

248254
if (BushyPlanFlag)
249255
{
250-
251256
/*
252257
* prune rels that have been completely incorporated into new
253258
* join rels

src/backend/parser/gram.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
*
241241
*
242242
* IDENTIFICATION
243-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/gram.c,v 2.66 1999/02/02 03:44:34 momjian Exp $
243+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/gram.c,v 2.67 1999/02/02 20:30:07 momjian Exp $
244244
*
245245
* HISTORY
246246
* AUTHOR DATE MAJOR EVENT
@@ -11450,11 +11450,17 @@ static Node *makeIndexable(char *opname, Node *lexpr, Node *rexpr)
1145011450
least->val.val.str = match_least;
1145111451
most->val.type = T_String;
1145211452
most->val.val.str = match_most;
11453+
#ifdef USE_LOCALE
11454+
result = makeA_Expr(AND, NULL,
11455+
makeA_Expr(OP, "~", lexpr, rexpr),
11456+
makeA_Expr(OP, ">=", lexpr, (Node *)least));
11457+
#else
1145311458
result = makeA_Expr(AND, NULL,
1145411459
makeA_Expr(OP, "~", lexpr, rexpr),
1145511460
makeA_Expr(AND, NULL,
1145611461
makeA_Expr(OP, ">=", lexpr, (Node *)least),
1145711462
makeA_Expr(OP, "<=", lexpr, (Node *)most)));
11463+
#endif
1145811464
}
1145911465
}
1146011466
}
@@ -11497,11 +11503,17 @@ static Node *makeIndexable(char *opname, Node *lexpr, Node *rexpr)
1149711503
least->val.val.str = match_least;
1149811504
most->val.type = T_String;
1149911505
most->val.val.str = match_most;
11506+
#ifdef USE_LOCALE
11507+
result = makeA_Expr(AND, NULL,
11508+
makeA_Expr(OP, "~~", lexpr, rexpr),
11509+
makeA_Expr(OP, ">=", lexpr, (Node *)least));
11510+
#else
1150011511
result = makeA_Expr(AND, NULL,
1150111512
makeA_Expr(OP, "~~", lexpr, rexpr),
1150211513
makeA_Expr(AND, NULL,
1150311514
makeA_Expr(OP, ">=", lexpr, (Node *)least),
1150411515
makeA_Expr(OP, "<=", lexpr, (Node *)most)));
11516+
#endif
1150511517
}
1150611518
}
1150711519
}

src/man/set.l

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/src/man/Attic/set.l,v 1.12 1999/02/02 03:45:33 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/set.l,v 1.13 1999/02/02 20:30:18 momjian Exp $
44
.TH SET SQL 05/14/97 PostgreSQL PostgreSQL
55
.SH NAME
66
set - set run-time parameters for session
@@ -44,7 +44,7 @@ determines the output format for the date and time data types.
4444
.IR GEQO
4545
enables or disables the genetic optimizer algorithm. This algorithm is
4646
.IR on
47-
by default, which used GEQO for statements of six or more tables.
47+
by default, which used GEQO for statements of six or more tables and indexes.
4848
Set the
4949
.IR Programmer's Guide
5050
for more information.
@@ -101,7 +101,7 @@ set DateStyle to 'SQL,European'
101101
.PP
102102
.nf
103103
--
104-
--Use GEQO for statements with 4 or more tables
104+
--Use GEQO for statements with 4 or more tables and indexes
105105
--
106106
set GEQO to 'on=4'
107107
--

0 commit comments

Comments
 (0)