7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.30 1999/08/23 23:48:39 tgl Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.31 1999/08/26 04:59:15 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -28,9 +28,7 @@ static Oid *oper_select_candidate(int nargs, Oid *input_typeids,
28
28
static Operator oper_exact (char * op , Oid arg1 , Oid arg2 );
29
29
static Operator oper_inexact (char * op , Oid arg1 , Oid arg2 );
30
30
static int binary_oper_get_candidates (char * opname ,
31
- Oid leftTypeId ,
32
- Oid rightTypeId ,
33
- CandidateList * candidates );
31
+ CandidateList * candidates );
34
32
static int unary_oper_get_candidates (char * op ,
35
33
Oid typeId ,
36
34
CandidateList * candidates ,
@@ -64,15 +62,12 @@ oprid(Operator op)
64
62
65
63
66
64
/* binary_oper_get_candidates()
67
- * given opname, leftTypeId and rightTypeId,
68
- * find all possible (arg1, arg2) pairs for which an operator named
69
- * opname exists, such that leftTypeId can be coerced to arg1 and
70
- * rightTypeId can be coerced to arg2
65
+ * given opname, find all possible input type pairs for which an operator
66
+ * named opname exists. Build a list of the candidate input types.
67
+ * Returns number of candidates found.
71
68
*/
72
69
static int
73
70
binary_oper_get_candidates (char * opname ,
74
- Oid leftTypeId ,
75
- Oid rightTypeId ,
76
71
CandidateList * candidates )
77
72
{
78
73
CandidateList current_candidate ;
@@ -224,14 +219,17 @@ oper_select_candidate(int nargs,
224
219
ncandidates ++ ;
225
220
}
226
221
/* otherwise, don't bother keeping this one... */
227
- else
228
- last_candidate -> next = NULL ;
229
222
}
230
223
224
+ if (last_candidate ) /* terminate rebuilt list */
225
+ last_candidate -> next = NULL ;
226
+
231
227
if (ncandidates <= 1 )
232
228
{
233
- if (!can_coerce_type (1 , & input_typeids [0 ], & candidates -> args [0 ])
234
- || !can_coerce_type (1 , & input_typeids [1 ], & candidates -> args [1 ]))
229
+ if (ncandidates > 0 &&
230
+ (!can_coerce_type (1 , & input_typeids [0 ], & candidates -> args [0 ]) ||
231
+ (nargs > 1 &&
232
+ !can_coerce_type (1 , & input_typeids [1 ], & candidates -> args [1 ]))))
235
233
ncandidates = 0 ;
236
234
return (ncandidates == 1 ) ? candidates -> args : NULL ;
237
235
}
@@ -252,9 +250,9 @@ oper_select_candidate(int nargs,
252
250
nmatch = 0 ;
253
251
for (i = 0 ; i < nargs ; i ++ )
254
252
{
255
- current_category = TypeCategory (current_typeids [i ]);
256
253
if (input_typeids [i ] != UNKNOWNOID )
257
254
{
255
+ current_category = TypeCategory (current_typeids [i ]);
258
256
if (current_typeids [i ] == input_typeids [i ])
259
257
nmatch ++ ;
260
258
else if (IsPreferredType (current_category , current_typeids [i ])
@@ -276,14 +274,17 @@ oper_select_candidate(int nargs,
276
274
last_candidate = current_candidate ;
277
275
ncandidates ++ ;
278
276
}
279
- else
280
- last_candidate -> next = NULL ;
281
277
}
282
278
279
+ if (last_candidate ) /* terminate rebuilt list */
280
+ last_candidate -> next = NULL ;
281
+
283
282
if (ncandidates <= 1 )
284
283
{
285
- if (!can_coerce_type (1 , & input_typeids [0 ], & candidates -> args [0 ])
286
- || ((nargs > 1 ) && !can_coerce_type (1 , & input_typeids [1 ], & candidates -> args [1 ])))
284
+ if (ncandidates > 0 &&
285
+ (!can_coerce_type (1 , & input_typeids [0 ], & candidates -> args [0 ]) ||
286
+ (nargs > 1 &&
287
+ !can_coerce_type (1 , & input_typeids [1 ], & candidates -> args [1 ]))))
287
288
ncandidates = 0 ;
288
289
return (ncandidates == 1 ) ? candidates -> args : NULL ;
289
290
}
@@ -309,12 +310,12 @@ oper_select_candidate(int nargs,
309
310
current_candidate != NULL ;
310
311
current_candidate = current_candidate -> next )
311
312
{
313
+ current_typeids = current_candidate -> args ;
312
314
nmatch = 0 ;
313
315
for (i = 0 ; i < nargs ; i ++ )
314
316
{
315
- current_typeids = current_candidate -> args ;
316
- if ((current_type == current_typeids [i ])
317
- || IS_BINARY_COMPATIBLE (current_type , current_typeids [i ]))
317
+ if (current_type == current_typeids [i ] ||
318
+ IS_BINARY_COMPATIBLE (current_type , current_typeids [i ]))
318
319
nmatch ++ ;
319
320
}
320
321
if (nmatch == nargs )
@@ -364,16 +365,20 @@ oper_select_candidate(int nargs,
364
365
}
365
366
366
367
ncandidates = 0 ;
368
+ last_candidate = NULL ;
367
369
for (current_candidate = candidates ;
368
370
current_candidate != NULL ;
369
371
current_candidate = current_candidate -> next )
370
372
{
371
373
if (can_coerce_type (1 , & input_typeids [0 ], & current_candidate -> args [0 ])
372
374
&& can_coerce_type (1 , & input_typeids [1 ], & current_candidate -> args [1 ]))
375
+ {
373
376
ncandidates ++ ;
377
+ last_candidate = current_candidate ;
378
+ }
374
379
}
375
380
376
- return (ncandidates == 1 ) ? candidates -> args : NULL ;
381
+ return (ncandidates == 1 ) ? last_candidate -> args : NULL ;
377
382
} /* oper_select_candidate() */
378
383
379
384
@@ -423,7 +428,7 @@ oper_inexact(char *op, Oid arg1, Oid arg2)
423
428
if (arg1 == InvalidOid )
424
429
arg1 = arg2 ;
425
430
426
- ncandidates = binary_oper_get_candidates (op , arg1 , arg2 , & candidates );
431
+ ncandidates = binary_oper_get_candidates (op , & candidates );
427
432
428
433
/* No operators found? Then return null... */
429
434
if (ncandidates == 0 )
0 commit comments