1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Cast constants to the type of the other binary operand.

Invalidate vacuum relation cache to use new row counts from vacuum.
This commit is contained in:
Bruce Momjian
1997-01-22 01:44:02 +00:00
parent a4ee68d1d4
commit 84876289cc
10 changed files with 104 additions and 25 deletions

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.19 1996/12/17 01:53:26 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.20 1997/01/22 01:42:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -1288,7 +1288,8 @@ make_targetlist_expr(ParseState *pstate,
val,
false,
true,
true /* is set */);
true, /* is set */
false);
} else {
lnext(expr) =
makeConst(attrtype,
@ -1297,7 +1298,8 @@ make_targetlist_expr(ParseState *pstate,
val,get_typelem(attrtype),-1),
false,
true /* Maybe correct-- 80% chance */,
false /* is not a set */);
false, /* is not a set */
false);
}
} else if((Typecast_ok) && (attrtype != type_id)){
lnext(expr) =

View File

@ -6,7 +6,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/catalog_utils.c,v 1.14 1996/12/26 17:47:41 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/catalog_utils.c,v 1.15 1997/01/22 01:43:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -1405,6 +1405,26 @@ typeid_get_retinfunc(Oid type_id)
return(infunc);
}
/* Given a type id, returns the out-conversion function of the type */
Oid
typeid_get_retoutfunc(Oid type_id)
{
HeapTuple typeTuple;
TypeTupleForm type;
Oid outfunc;
typeTuple = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(type_id),
0,0,0);
if ( !HeapTupleIsValid ( typeTuple ))
elog(WARN,
"typeid_get_retoutfunc: Invalid type - oid = %u",
type_id);
type = (TypeTupleForm) GETSTRUCT(typeTuple);
outfunc = type->typoutput;
return(outfunc);
}
Oid
typeid_get_relid(Oid type_id)
{

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/parse_query.c,v 1.11 1996/12/07 04:38:10 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/parse_query.c,v 1.12 1997/01/22 01:43:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -367,10 +367,50 @@ make_op(char *opname, Node *ltree, Node *rtree)
left = NULL;
}else {
char *outstr;
Oid infunc, outfunc;
Type newtype;
#define CONVERTABLE_TYPE(t) ( (t) == INT2OID || \
(t) == INT4OID || \
(t) == OIDOID || \
(t) == FLOAT4OID || \
(t) == FLOAT8OID)
/* binary operator */
ltypeId = (ltree==NULL) ? UNKNOWNOID : exprType(ltree);
rtypeId = (rtree==NULL) ? UNKNOWNOID : exprType(rtree);
/* convert constant when using a const of a numeric type
and a non-const of another numeric type */
if (CONVERTABLE_TYPE(ltypeId) && nodeTag(ltree) != T_Const &&
CONVERTABLE_TYPE(rtypeId) && nodeTag(rtree) == T_Const &&
!((Const *)rtree)->constiscast) {
outfunc = typeid_get_retoutfunc(rtypeId);
infunc = typeid_get_retinfunc(ltypeId);
outstr = (char *)fmgr(outfunc, ((Const *)rtree)->constvalue);
((Const *)rtree)->constvalue = (Datum)fmgr(infunc, outstr);
pfree(outstr);
((Const *)rtree)->consttype = rtypeId = ltypeId;
newtype = get_id_type(rtypeId);
((Const *)rtree)->constlen = tlen(newtype);
((Const *)rtree)->constbyval = tbyval(newtype);
}
if (CONVERTABLE_TYPE(rtypeId) && nodeTag(rtree) != T_Const &&
CONVERTABLE_TYPE(ltypeId) && nodeTag(ltree) == T_Const &&
!((Const *)ltree)->constiscast) {
outfunc = typeid_get_retoutfunc(ltypeId);
infunc = typeid_get_retinfunc(rtypeId);
outstr = (char *)fmgr(outfunc, ((Const *)ltree)->constvalue);
((Const *)ltree)->constvalue = (Datum)fmgr(infunc, outstr);
pfree(outstr);
((Const *)ltree)->consttype = ltypeId = rtypeId;
newtype = get_id_type(ltypeId);
((Const *)ltree)->constlen = tlen(newtype);
((Const *)ltree)->constbyval = tbyval(newtype);
}
temp = oper(opname, ltypeId, rtypeId);
opform = (OperatorTupleForm) GETSTRUCT(temp);
left = make_operand(opname, ltree, ltypeId, opform->oprleft);
@ -654,7 +694,7 @@ make_const(Value *value)
elog(NOTICE,"unknown type : %d\n", nodeTag(value));
/* null const */
con = makeConst(0, 0, (Datum)NULL, TRUE, 0, FALSE);
con = makeConst(0, 0, (Datum)NULL, true, false, false, false);
return con;
}
}
@ -662,9 +702,10 @@ make_const(Value *value)
con = makeConst(typeid(tp),
tlen(tp),
val,
FALSE,
false,
tbyval(tp),
FALSE); /* not a set */
false, /* not a set */
false);
return (con);
}

View File

@ -6,7 +6,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.16 1996/12/26 17:47:42 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.17 1997/01/22 01:43:26 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -283,9 +283,10 @@ parser_typecast(Value *expr, TypeName *typename, int typlen)
adt = makeConst(typeid(tp),
len,
(Datum)lcp ,
0,
false,
tbyvalue(tp),
0 /* not a set */);
false, /* not a set */
true /* is cast */);
if (string_palloced)
pfree(const_string);
@ -365,8 +366,9 @@ parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen)
(Size) 0,
(Datum) NULL,
true, /* isnull */
0 /* was omitted */,
0 /* not a set */);
false, /* was omitted */
false, /* not a set */
true /* is cast */);
return ((Node*) adt);
}
@ -401,9 +403,10 @@ parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen)
adt = makeConst(typeid(tp),
(Size)len,
(Datum)lcp,
0,
0 /*was omitted*/,
0 /* not a set */);
false,
false, /*was omitted*/
false, /* not a set */
true /* is cast */);
/*
printf("adt %s : %u %d %d\n",CString(expr),typeid(tp) ,
len,cp);