5
5
*
6
6
* Copyright (c) 1994, Regents of the University of California
7
7
*
8
- * $Id: geqo_eval.c,v 1.35 1999/02/18 05:26:18 momjian Exp $
8
+ * $Id: geqo_eval.c,v 1.36 1999/05/16 19:45:00 tgl Exp $
9
9
*
10
10
*-------------------------------------------------------------------------
11
11
*/
48
48
#include "optimizer/geqo_gene.h"
49
49
#include "optimizer/geqo.h"
50
50
51
- static RelOptInfo * geqo_nth (int stop , List * rels );
52
-
53
51
/*
54
52
* geqo_eval
55
53
*
@@ -62,31 +60,28 @@ geqo_eval(Query *root, Gene *tour, int num_gene)
62
60
Cost fitness ;
63
61
List * temp ;
64
62
65
-
66
- /* remember root->join_rel_list ... */
67
- /* because root->join_rel_list will be changed during the following */
63
+ /* remember root->join_rel_list ... */
64
+ /* because root->join_rel_list will be changed during the following */
68
65
temp = listCopy (root -> join_rel_list );
69
66
70
- /* joinrel is readily processed query tree -- left-sided ! */
67
+ /* joinrel is readily processed query tree -- left-sided ! */
71
68
joinrel = gimme_tree (root , tour , 0 , num_gene , NULL );
72
69
73
- /* compute fitness */
70
+ /* compute fitness */
74
71
fitness = (Cost ) joinrel -> cheapestpath -> path_cost ;
75
72
76
- root -> join_rel_list = listCopy ( temp ) ;
73
+ root -> join_rel_list = temp ;
77
74
78
75
pfree (joinrel );
79
- freeList (temp );
80
76
81
77
return fitness ;
82
-
83
78
}
84
79
85
80
/*
86
81
* gimme_tree
87
82
* this program presumes that only LEFT-SIDED TREES are considered!
88
83
*
89
- * 'old_rel' is the preceeding join
84
+ * 'old_rel' is the preceding join
90
85
*
91
86
* Returns a new join relation incorporating all joins in a left-sided tree.
92
87
*/
@@ -95,17 +90,16 @@ gimme_tree(Query *root, Gene *tour, int rel_count, int num_gene, RelOptInfo *old
95
90
{
96
91
RelOptInfo * inner_rel ; /* current relation */
97
92
int base_rel_index ;
98
-
99
- List * new_rels = NIL ;
100
- RelOptInfo * new_rel = NULL ;
93
+ List * new_rels ;
94
+ RelOptInfo * new_rel ;
101
95
102
96
if (rel_count < num_gene )
103
97
{ /* tree not yet finished */
104
98
105
99
/* tour[0] = 3; tour[1] = 1; tour[2] = 2 */
106
100
base_rel_index = (int ) tour [rel_count ];
107
101
108
- inner_rel = (RelOptInfo * ) geqo_nth (base_rel_index , root -> base_rel_list );
102
+ inner_rel = (RelOptInfo * ) nth (base_rel_index - 1 , root -> base_rel_list );
109
103
110
104
if (rel_count == 0 )
111
105
{ /* processing first join with
@@ -116,11 +110,11 @@ gimme_tree(Query *root, Gene *tour, int rel_count, int num_gene, RelOptInfo *old
116
110
else
117
111
{ /* tree main part */
118
112
if (!(new_rels = make_rels_by_clause_joins (root , old_rel ,
119
- inner_rel -> joininfo ,
113
+ old_rel -> joininfo ,
120
114
inner_rel -> relids )))
121
115
{
122
116
new_rels = make_rels_by_clauseless_joins (old_rel ,
123
- lcons (inner_rel ,NIL ));
117
+ lcons (inner_rel ,NIL ));
124
118
/* we don't do bushy plans in geqo, do we? bjm 02/18/1999
125
119
new_rels = append(new_rels,
126
120
make_rels_by_clauseless_joins(old_rel,
@@ -151,12 +145,12 @@ gimme_tree(Query *root, Gene *tour, int rel_count, int num_gene, RelOptInfo *old
151
145
elog (DEBUG , "gimme_tree: still %d relations left" , length (new_rels ));
152
146
}
153
147
148
+ rels_set_cheapest (new_rels );
149
+
154
150
/* get essential new relation */
155
151
new_rel = (RelOptInfo * ) lfirst (new_rels );
156
152
rel_count ++ ;
157
153
158
- set_cheapest (new_rel , new_rel -> pathlist );
159
-
160
154
/* processing of other new_rel attributes */
161
155
if (new_rel -> size <= 0 )
162
156
new_rel -> size = compute_rel_size (new_rel );
@@ -166,24 +160,7 @@ gimme_tree(Query *root, Gene *tour, int rel_count, int num_gene, RelOptInfo *old
166
160
167
161
return gimme_tree (root , tour , rel_count , num_gene , new_rel );
168
162
}
169
-
170
163
}
171
164
172
165
return old_rel ; /* tree finished ... */
173
166
}
174
-
175
- static RelOptInfo *
176
- geqo_nth (int stop , List * rels )
177
- {
178
- List * r ;
179
- int i = 1 ;
180
-
181
- foreach (r , rels )
182
- {
183
- if (i == stop )
184
- return lfirst (r );
185
- i ++ ;
186
- }
187
- elog (ERROR , "geqo_nth: Internal error - ran off end of list" );
188
- return NULL ; /* to keep compiler happy */
189
- }
0 commit comments