7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.23 1999/02/10 21:02 :43 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.24 1999/02/11 04:08 :43 momjian Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
29
29
30
30
#include "parser/parsetree.h" /* for getrelid() */
31
31
32
- static Path * better_path (Path * new_path , List * unique_paths , bool * noOther );
32
+ static Path * better_path (Path * new_path , List * unique_paths , bool * isNew );
33
33
34
34
35
35
/*****************************************************************************
@@ -107,16 +107,16 @@ add_pathlist(RelOptInfo *parent_rel, List *unique_paths, List *new_paths)
107
107
{
108
108
Path * new_path = (Path * ) lfirst (p1 );
109
109
Path * old_path ;
110
- bool noOther ;
110
+ bool is_new ;
111
111
112
112
/* Is this new path already in unique_paths? */
113
113
if (member (new_path , unique_paths ))
114
114
continue ;
115
115
116
116
/* Find best matching path */
117
- old_path = better_path (new_path , unique_paths , & noOther );
117
+ old_path = better_path (new_path , unique_paths , & is_new );
118
118
119
- if (noOther )
119
+ if (is_new )
120
120
{
121
121
/* This is a brand new path. */
122
122
new_path -> parent = parent_rel ;
@@ -153,19 +153,19 @@ add_pathlist(RelOptInfo *parent_rel, List *unique_paths, List *new_paths)
153
153
*
154
154
*/
155
155
static Path *
156
- better_path (Path * new_path , List * unique_paths , bool * noOther )
156
+ better_path (Path * new_path , List * unique_paths , bool * is_new )
157
157
{
158
- Path * old_path = (Path * ) NULL ;
159
158
Path * path = (Path * ) NULL ;
160
159
List * temp = NIL ;
161
- Path * retval = NULL ;
160
+ int longer_key ;
162
161
163
162
foreach (temp , unique_paths )
164
163
{
165
164
path = (Path * ) lfirst (temp );
166
165
167
166
#ifdef OPTDUP_DEBUG
168
- if (!samekeys (path -> pathkeys , new_path -> pathkeys ))
167
+ if (!pathkeys_match (new_path -> pathkeys , path -> pathkeys , & longer_key ) ||
168
+ longer_key != 0 )
169
169
{
170
170
printf ("oldpath\n" );
171
171
pprint (path -> pathkeys );
@@ -176,35 +176,43 @@ better_path(Path *new_path, List *unique_paths, bool *noOther)
176
176
length (lfirst (path -> pathkeys )) < length (lfirst (new_path -> pathkeys )))
177
177
sleep (0 ); /* set breakpoint here */
178
178
}
179
- if (!equal_path_ordering (path -> path_order ,
180
- new_path -> path_order ))
179
+ if (!equal_path_ordering (new_path -> path_order , path -> path_order ))
181
180
{
182
181
printf ("oldord\n" );
183
182
pprint (path -> path_order );
184
183
printf ("neword\n" );
185
184
pprint (new_path -> path_order );
186
185
}
187
186
#endif
188
-
189
- if (samekeys (path -> pathkeys , new_path -> pathkeys ) &&
190
- equal_path_ordering (path -> path_order ,
191
- new_path -> path_order ))
187
+
188
+ if (pathkeys_match (new_path -> pathkeys , path -> pathkeys , & longer_key ))
192
189
{
193
- old_path = path ;
194
- break ;
190
+ if (equal_path_ordering (new_path -> path_order , path -> path_order ))
191
+ {
192
+ /*
193
+ * Replace pathkeys that match exactly, (1,2), (1,2).
194
+ * Replace pathkeys (1,2) with (1,2,3) if the latter is not
195
+ * more expensive and replace unordered path with ordered
196
+ * path if it is not more expensive.
197
+ */
198
+ if ((longer_key == 0 && new_path -> path_cost < path -> path_cost ) ||
199
+ (longer_key == 1 && new_path -> path_cost <= path -> path_cost ) ||
200
+ (longer_key == 2 && new_path -> path_cost >= path -> path_cost ))
201
+ {
202
+ * is_new = false;
203
+ return new_path ;
204
+ }
205
+ else
206
+ {
207
+ * is_new = false;
208
+ return NULL ;
209
+ }
210
+ }
195
211
}
196
212
}
197
213
198
- if (old_path == NULL )
199
- * noOther = true;
200
- else
201
- {
202
- * noOther = false;
203
- if (path_is_cheaper (new_path , old_path ))
204
- retval = old_path ;
205
- }
206
-
207
- return retval ;
214
+ * is_new = true;
215
+ return NULL ;
208
216
}
209
217
210
218
0 commit comments