Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a23faee

Browse files
committed
Remove bogus code in oper_exact --- if it didn't find an exact
match then it tried for a self-commutative operator with the reversed input data types. This is pretty silly; there could never be such an operator, except maybe in binary-compatible-type scenarios, and we have oper_inexact for that. Besides which, the oprsanity regress test would complain about such an operator. Remove nonfunctional code and simplify routine calling convention accordingly.
1 parent e8140ad commit a23faee

File tree

4 files changed

+33
-105
lines changed

4 files changed

+33
-105
lines changed

src/backend/parser/parse_node.c

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.30 1999/08/22 20:15:04 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.31 1999/08/23 23:48:39 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -31,10 +31,6 @@
3131
#include "utils/syscache.h"
3232

3333
static void disallow_setop(char *op, Type optype, Node *operand);
34-
static Node *make_operand(char *opname,
35-
Node *tree,
36-
Oid orig_typeId,
37-
Oid true_typeId);
3834

3935
/* make_parsestate()
4036
* Allocate and initialize a new ParseState.
@@ -58,31 +54,31 @@ make_parsestate(ParseState *parentParseState)
5854
/* make_operand()
5955
* Ensure argument type match by forcing conversion of constants.
6056
*/
61-
static Node *
57+
Node *
6258
make_operand(char *opname,
6359
Node *tree,
6460
Oid orig_typeId,
65-
Oid true_typeId)
61+
Oid target_typeId)
6662
{
6763
Node *result;
68-
Type true_type;
64+
Type target_type;
6965

7066
if (tree != NULL)
7167
{
7268
result = tree;
73-
true_type = typeidType(true_typeId);
74-
disallow_setop(opname, true_type, result);
69+
target_type = typeidType(target_typeId);
70+
disallow_setop(opname, target_type, result);
7571

7672
/* must coerce? */
77-
if (true_typeId != orig_typeId)
78-
result = coerce_type(NULL, tree, orig_typeId, true_typeId, -1);
73+
if (target_typeId != orig_typeId)
74+
result = coerce_type(NULL, tree, orig_typeId, target_typeId, -1);
7975
}
8076
/* otherwise, this is a NULL value */
8177
else
8278
{
8379
Const *con = makeNode(Const);
8480

85-
con->consttype = true_typeId;
81+
con->consttype = target_typeId;
8682
con->constlen = 0;
8783
con->constvalue = (Datum) (struct varlena *) NULL;
8884
con->constisnull = true;
@@ -128,47 +124,31 @@ make_op(char *opname, Node *ltree, Node *rtree)
128124
*right;
129125
Expr *result;
130126

127+
ltypeId = (ltree == NULL) ? UNKNOWNOID : exprType(ltree);
128+
rtypeId = (rtree == NULL) ? UNKNOWNOID : exprType(rtree);
129+
131130
/* right operator? */
132131
if (rtree == NULL)
133132
{
134-
ltypeId = (ltree == NULL) ? UNKNOWNOID : exprType(ltree);
135133
tup = right_oper(opname, ltypeId);
136134
opform = (Form_pg_operator) GETSTRUCT(tup);
137135
left = make_operand(opname, ltree, ltypeId, opform->oprleft);
138136
right = NULL;
139-
140137
}
141138

142139
/* left operator? */
143140
else if (ltree == NULL)
144141
{
145-
rtypeId = (rtree == NULL) ? UNKNOWNOID : exprType(rtree);
146142
tup = left_oper(opname, rtypeId);
147143
opform = (Form_pg_operator) GETSTRUCT(tup);
148144
right = make_operand(opname, rtree, rtypeId, opform->oprright);
149145
left = NULL;
150-
151146
}
152147

153148
/* otherwise, binary operator */
154149
else
155150
{
156-
/* binary operator */
157-
ltypeId = (ltree == NULL) ? UNKNOWNOID : exprType(ltree);
158-
rtypeId = (rtree == NULL) ? UNKNOWNOID : exprType(rtree);
159-
160-
/* check for exact match on this operator... */
161-
if (HeapTupleIsValid(tup = oper_exact(opname, ltypeId, rtypeId, &ltree, &rtree, TRUE)))
162-
{
163-
ltypeId = exprType(ltree);
164-
rtypeId = exprType(rtree);
165-
}
166-
/* try to find a match on likely candidates... */
167-
else if (!HeapTupleIsValid(tup = oper_inexact(opname, ltypeId, rtypeId, &ltree, &rtree, FALSE)))
168-
{
169-
/* Won't return from oper_inexact() without a candidate... */
170-
}
171-
151+
tup = oper(opname, ltypeId, rtypeId, FALSE);
172152
opform = (Form_pg_operator) GETSTRUCT(tup);
173153
left = make_operand(opname, ltree, ltypeId, opform->oprleft);
174154
right = make_operand(opname, rtree, rtypeId, opform->oprright);

src/backend/parser/parse_oper.c

Lines changed: 16 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.29 1999/07/17 20:17:25 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.30 1999/08/23 23:48:39 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -25,6 +25,8 @@
2525

2626
static Oid *oper_select_candidate(int nargs, Oid *input_typeids,
2727
CandidateList candidates);
28+
static Operator oper_exact(char *op, Oid arg1, Oid arg2);
29+
static Operator oper_inexact(char *op, Oid arg1, Oid arg2);
2830
static int binary_oper_get_candidates(char *opname,
2931
Oid leftTypeId,
3032
Oid rightTypeId,
@@ -376,15 +378,14 @@ oper_select_candidate(int nargs,
376378

377379

378380
/* oper_exact()
379-
* Given operator, and arguments, return oper struct.
381+
* Given operator, and arguments, return oper struct or NULL.
380382
* Inputs:
381383
* arg1, arg2: Type IDs
382384
*/
383-
Operator
384-
oper_exact(char *op, Oid arg1, Oid arg2, Node **ltree, Node **rtree, bool noWarnings)
385+
static Operator
386+
oper_exact(char *op, Oid arg1, Oid arg2)
385387
{
386388
HeapTuple tup;
387-
Node *tree;
388389

389390
/* Unspecified type for one of the arguments? then use the other */
390391
if ((arg1 == UNKNOWNOID) && (arg2 != InvalidOid))
@@ -398,51 +399,17 @@ oper_exact(char *op, Oid arg1, Oid arg2, Node **ltree, Node **rtree, bool noWarn
398399
ObjectIdGetDatum(arg2),
399400
CharGetDatum('b'));
400401

401-
/*
402-
* Did not find anything? then try flipping arguments on a commutative
403-
* operator...
404-
*/
405-
if (!HeapTupleIsValid(tup) && (arg1 != arg2))
406-
{
407-
tup = SearchSysCacheTuple(OPRNAME,
408-
PointerGetDatum(op),
409-
ObjectIdGetDatum(arg2),
410-
ObjectIdGetDatum(arg1),
411-
CharGetDatum('b'));
412-
413-
if (HeapTupleIsValid(tup))
414-
{
415-
Form_pg_operator opform;
416-
417-
opform = (Form_pg_operator) GETSTRUCT(tup);
418-
if (opform->oprcom == tup->t_data->t_oid)
419-
{
420-
if ((ltree != NULL) && (rtree != NULL))
421-
{
422-
tree = *ltree;
423-
*ltree = *rtree;
424-
*rtree = tree;
425-
}
426-
}
427-
/* disable for now... - thomas 1998-05-14 */
428-
else
429-
tup = NULL;
430-
}
431-
if (!HeapTupleIsValid(tup) && (!noWarnings))
432-
op_error(op, arg1, arg2);
433-
}
434-
435-
return tup;
402+
return (Operator) tup;
436403
} /* oper_exact() */
437404

438405

439406
/* oper_inexact()
440-
* Given operator, types of arg1, and arg2, return oper struct.
407+
* Given operator, types of arg1, and arg2, return oper struct or NULL.
441408
* Inputs:
442409
* arg1, arg2: Type IDs
443410
*/
444-
Operator
445-
oper_inexact(char *op, Oid arg1, Oid arg2, Node **ltree, Node **rtree, bool noWarnings)
411+
static Operator
412+
oper_inexact(char *op, Oid arg1, Oid arg2)
446413
{
447414
HeapTuple tup;
448415
CandidateList candidates;
@@ -458,13 +425,9 @@ oper_inexact(char *op, Oid arg1, Oid arg2, Node **ltree, Node **rtree, bool noWa
458425

459426
ncandidates = binary_oper_get_candidates(op, arg1, arg2, &candidates);
460427

461-
/* No operators found? Then throw error or return null... */
428+
/* No operators found? Then return null... */
462429
if (ncandidates == 0)
463-
{
464-
if (!noWarnings)
465-
op_error(op, arg1, arg2);
466430
return NULL;
467-
}
468431

469432
/* Or found exactly one? Then proceed... */
470433
else if (ncandidates == 1)
@@ -493,18 +456,6 @@ oper_inexact(char *op, Oid arg1, Oid arg2, Node **ltree, Node **rtree, bool noWa
493456
}
494457
else
495458
tup = NULL;
496-
497-
/* Could not choose one, for whatever reason... */
498-
if (!HeapTupleIsValid(tup))
499-
{
500-
if (!noWarnings)
501-
{
502-
elog(ERROR, "Unable to identify an operator '%s' for types '%s' and '%s'"
503-
"\n\tYou will have to retype this query using an explicit cast",
504-
op, typeTypeName(typeidType(arg1)), typeTypeName(typeidType(arg2)));
505-
}
506-
return NULL;
507-
}
508459
}
509460
return (Operator) tup;
510461
} /* oper_inexact() */
@@ -521,17 +472,16 @@ oper(char *opname, Oid ltypeId, Oid rtypeId, bool noWarnings)
521472
HeapTuple tup;
522473

523474
/* check for exact match on this operator... */
524-
if (HeapTupleIsValid(tup = oper_exact(opname, ltypeId, rtypeId, NULL, NULL, TRUE)))
475+
if (HeapTupleIsValid(tup = oper_exact(opname, ltypeId, rtypeId)))
525476
{
526477
}
527478
/* try to find a match on likely candidates... */
528-
else if (HeapTupleIsValid(tup = oper_inexact(opname, ltypeId, rtypeId, NULL, NULL, TRUE)))
479+
else if (HeapTupleIsValid(tup = oper_inexact(opname, ltypeId, rtypeId)))
529480
{
530481
}
531482
else if (!noWarnings)
532483
{
533-
elog(ERROR, "Unable to identify a binary operator '%s' for types %s and %s",
534-
opname, typeTypeName(typeidType(ltypeId)), typeTypeName(typeidType(rtypeId)));
484+
op_error(opname, ltypeId, rtypeId);
535485
}
536486

537487
return (Operator) tup;
@@ -741,8 +691,7 @@ op_error(char *op, Oid arg1, Oid arg2)
741691
"\n\tProbably a bad attribute name", op);
742692
}
743693

744-
elog(ERROR, "There is no operator '%s' for types '%s' and '%s'"
745-
"\n\tYou will either have to retype this query using an explicit cast,"
746-
"\n\tor you will have to define the operator using CREATE OPERATOR",
694+
elog(ERROR, "Unable to identify an operator '%s' for types '%s' and '%s'"
695+
"\n\tYou will have to retype this query using an explicit cast",
747696
op, typeTypeName(tp1), typeTypeName(tp2));
748697
}

src/include/parser/parse_node.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: parse_node.h,v 1.15 1999/07/19 00:26:17 tgl Exp $
8+
* $Id: parse_node.h,v 1.16 1999/08/23 23:48:37 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -33,6 +33,8 @@ typedef struct ParseState
3333

3434
extern ParseState *make_parsestate(ParseState *parentParseState);
3535
extern Expr *make_op(char *opname, Node *ltree, Node *rtree);
36+
extern Node *make_operand(char *opname, Node *tree,
37+
Oid orig_typeId, Oid target_typeId);
3638
extern Var *make_var(ParseState *pstate, Oid relid, char *refname,
3739
char *attrname);
3840
extern ArrayRef *transformArraySubscripts(ParseState *pstate,

src/include/parser/parse_oper.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: parse_oper.h,v 1.8 1999/07/15 15:21:27 momjian Exp $
9+
* $Id: parse_oper.h,v 1.9 1999/08/23 23:48:38 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -23,7 +23,4 @@ extern Operator oper(char *op, Oid arg1, Oid arg2, bool noWarnings);
2323
extern Operator right_oper(char *op, Oid arg);
2424
extern Operator left_oper(char *op, Oid arg);
2525

26-
extern Operator oper_exact(char *op, Oid arg1, Oid arg2, Node **ltree, Node **rtree, bool noWarnings);
27-
extern Operator oper_inexact(char *op, Oid arg1, Oid arg2, Node **ltree, Node **rtree, bool noWarnings);
28-
2926
#endif /* PARSE_OPER_H */

0 commit comments

Comments
 (0)