7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/pathkey.c,v 1.1 1999/02/18 19:58:52 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/pathkey.c,v 1.2 1999/02/19 02:05:15 momjian Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
27
27
28
28
29
29
static int match_pathkey_joinkeys (List * pathkey , List * joinkeys ,
30
- int which_subkey );
30
+ int outer_or_inner );
31
31
static bool every_func (List * joinkeys , List * pathkey ,
32
- int which_subkey );
32
+ int outer_or_inner );
33
33
static List * new_join_pathkey (List * subkeys , List * considered_subkeys ,
34
34
List * join_rel_tlist , List * joinclauses );
35
35
static List * new_matching_subkeys (Var * subkey , List * considered_subkeys ,
@@ -54,7 +54,7 @@ static List *new_matching_subkeys(Var *subkey, List *considered_subkeys,
54
54
* ( (outer inner) (outer inner) ... )
55
55
* 'joinclauses' is a list of clauses corresponding to the join keys in
56
56
* 'joinkeys'
57
- * 'which_subkey ' is a flag that selects the desired subkey of a join key
57
+ * 'outer_or_inner ' is a flag that selects the desired subkey of a join key
58
58
* in 'joinkeys'
59
59
*
60
60
* Returns the join keys and corresponding join clauses in a list if all
72
72
match_pathkeys_joinkeys (List * pathkeys ,
73
73
List * joinkeys ,
74
74
List * joinclauses ,
75
- int which_subkey ,
75
+ int outer_or_inner ,
76
76
List * * matchedJoinClausesPtr )
77
77
{
78
78
List * matched_joinkeys = NIL ;
@@ -84,19 +84,17 @@ match_pathkeys_joinkeys(List *pathkeys,
84
84
foreach (i , pathkeys )
85
85
{
86
86
pathkey = lfirst (i );
87
- matched_joinkey_index = match_pathkey_joinkeys (pathkey , joinkeys , which_subkey );
87
+ matched_joinkey_index = match_pathkey_joinkeys (pathkey , joinkeys ,
88
+ outer_or_inner );
88
89
89
90
if (matched_joinkey_index != -1 )
90
91
{
91
92
List * xjoinkey = nth (matched_joinkey_index , joinkeys );
92
93
List * joinclause = nth (matched_joinkey_index , joinclauses );
93
94
94
- /* XXX was "push" function */
95
- matched_joinkeys = lappend (matched_joinkeys , xjoinkey );
96
- matched_joinkeys = nreverse (matched_joinkeys );
95
+ matched_joinkeys = lcons (xjoinkey , matched_joinkeys );
96
+ matched_joinclauses = lcons (joinclause , matched_joinclauses );
97
97
98
- matched_joinclauses = lappend (matched_joinclauses , joinclause );
99
- matched_joinclauses = nreverse (matched_joinclauses );
100
98
joinkeys = LispRemove (xjoinkey , joinkeys );
101
99
}
102
100
else
@@ -111,6 +109,7 @@ match_pathkeys_joinkeys(List *pathkeys,
111
109
return nreverse (matched_joinkeys );
112
110
}
113
111
112
+
114
113
/*
115
114
* match_pathkey_joinkeys
116
115
* Returns the 0-based index into 'joinkeys' of the first joinkey whose
@@ -119,7 +118,7 @@ match_pathkeys_joinkeys(List *pathkeys,
119
118
static int
120
119
match_pathkey_joinkeys (List * pathkey ,
121
120
List * joinkeys ,
122
- int which_subkey )
121
+ int outer_or_inner )
123
122
{
124
123
Var * path_subkey ;
125
124
int pos ;
@@ -135,14 +134,15 @@ match_pathkey_joinkeys(List *pathkey,
135
134
{
136
135
jk = (JoinKey * ) lfirst (x );
137
136
if (var_equal (path_subkey ,
138
- extract_join_subkey (jk , which_subkey )))
137
+ extract_join_key (jk , outer_or_inner )))
139
138
return pos ;
140
139
pos ++ ;
141
140
}
142
141
}
143
142
return -1 ; /* no index found */
144
143
}
145
144
145
+
146
146
/*
147
147
* match_paths_joinkeys
148
148
* Attempts to find a path in 'paths' whose keys match a set of join
@@ -159,53 +159,16 @@ match_pathkey_joinkeys(List *pathkey,
159
159
* must correspond
160
160
* 'paths' is a list of(inner) paths which are to be matched against
161
161
* each join key in 'joinkeys'
162
- * 'which_subkey ' is a flag that selects the desired subkey of a join key
162
+ * 'outer_or_inner ' is a flag that selects the desired subkey of a join key
163
163
* in 'joinkeys'
164
164
*
165
- * Returns the matching path node if one exists, nil otherwise.
166
- */
167
- static bool
168
- every_func (List * joinkeys , List * pathkey , int which_subkey )
169
- {
170
- JoinKey * xjoinkey ;
171
- Var * temp ;
172
- Var * tempkey = NULL ;
173
- bool found = false;
174
- List * i = NIL ;
175
- List * j = NIL ;
176
-
177
- foreach (i , joinkeys )
178
- {
179
- xjoinkey = (JoinKey * ) lfirst (i );
180
- found = false;
181
- foreach (j , pathkey )
182
- {
183
- temp = (Var * ) lfirst ((List * ) lfirst (j ));
184
- if (temp == NULL )
185
- continue ;
186
- tempkey = extract_join_subkey (xjoinkey , which_subkey );
187
- if (var_equal (tempkey , temp ))
188
- {
189
- found = true;
190
- break ;
191
- }
192
- }
193
- if (found == false)
194
- return false;
195
- }
196
- return found ;
197
- }
198
-
199
-
200
- /*
201
- * match_paths_joinkeys -
202
- * find the cheapest path that matches the join keys
165
+ * Find the cheapest path that matches the join keys
203
166
*/
204
167
Path *
205
168
match_paths_joinkeys (List * joinkeys ,
206
169
PathOrder * ordering ,
207
170
List * paths ,
208
- int which_subkey )
171
+ int outer_or_inner )
209
172
{
210
173
Path * matched_path = NULL ;
211
174
bool key_match = false;
@@ -216,13 +179,12 @@ match_paths_joinkeys(List *joinkeys,
216
179
Path * path = (Path * ) lfirst (i );
217
180
int better_sort ;
218
181
219
- key_match = every_func (joinkeys , path -> pathkeys , which_subkey );
182
+ key_match = every_func (joinkeys , path -> pathkeys , outer_or_inner );
220
183
221
184
if (pathorder_match (ordering , path -> pathorder , & better_sort ) &&
222
185
better_sort == 0 &&
223
186
length (joinkeys ) == length (path -> pathkeys ) && key_match )
224
187
{
225
-
226
188
if (matched_path )
227
189
{
228
190
if (path -> path_cost < matched_path -> path_cost )
@@ -236,7 +198,6 @@ match_paths_joinkeys(List *joinkeys,
236
198
}
237
199
238
200
239
-
240
201
/*
241
202
* extract_path_keys
242
203
* Builds a subkey list for a path by pulling one of the subkeys from
@@ -245,7 +206,7 @@ match_paths_joinkeys(List *joinkeys,
245
206
*
246
207
* 'joinkeys' is a list of join key pairs
247
208
* 'tlist' is a relation target list
248
- * 'which_subkey ' is a flag that selects the desired subkey of a join key
209
+ * 'outer_or_inner ' is a flag that selects the desired subkey of a join key
249
210
* in 'joinkeys'
250
211
*
251
212
* Returns a list of pathkeys: ((tlvar1)(tlvar2)...(tlvarN)).
@@ -254,7 +215,7 @@ match_paths_joinkeys(List *joinkeys,
254
215
List *
255
216
extract_path_keys (List * joinkeys ,
256
217
List * tlist ,
257
- int which_subkey )
218
+ int outer_or_inner )
258
219
{
259
220
List * pathkeys = NIL ;
260
221
List * jk ;
@@ -269,7 +230,7 @@ extract_path_keys(List *joinkeys,
269
230
/*
270
231
* find the right Var in the target list for this key
271
232
*/
272
- var = (Var * ) extract_join_subkey (jkey , which_subkey );
233
+ var = (Var * ) extract_join_key (jkey , outer_or_inner );
273
234
key = (Var * ) matching_tlist_var (var , tlist );
274
235
275
236
/*
@@ -291,6 +252,42 @@ extract_path_keys(List *joinkeys,
291
252
}
292
253
293
254
255
+ /*
256
+ * every_func
257
+ */
258
+ static bool
259
+ every_func (List * joinkeys , List * pathkey , int outer_or_inner )
260
+ {
261
+ JoinKey * xjoinkey ;
262
+ Var * temp ;
263
+ Var * tempkey = NULL ;
264
+ bool found = false;
265
+ List * i = NIL ;
266
+ List * j = NIL ;
267
+
268
+ foreach (i , joinkeys )
269
+ {
270
+ xjoinkey = (JoinKey * ) lfirst (i );
271
+ found = false;
272
+ foreach (j , pathkey )
273
+ {
274
+ temp = (Var * ) lfirst ((List * ) lfirst (j ));
275
+ if (temp == NULL )
276
+ continue ;
277
+ tempkey = extract_join_key (xjoinkey , outer_or_inner );
278
+ if (var_equal (tempkey , temp ))
279
+ {
280
+ found = true;
281
+ break ;
282
+ }
283
+ }
284
+ if (found == false)
285
+ return false;
286
+ }
287
+ return found ;
288
+ }
289
+
290
+
294
291
/****************************************************************************
295
292
* NEW PATHKEY FORMATION
296
293
****************************************************************************/
0 commit comments