Commit 84876289 authored by Bruce Momjian's avatar Bruce Momjian

Cast constants to the type of the other binary operand.

Invalidate vacuum relation cache to use new row counts from vacuum.
parent a4ee68d1
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.14 1997/01/13 03:43:59 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.15 1997/01/22 01:42:16 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -29,10 +29,12 @@
#include <catalog/pg_index.h>
#include <catalog/index.h>
#include <catalog/catname.h>
#include <catalog/catalog.h>
#include <catalog/pg_class.h>
#include <catalog/pg_proc.h>
#include <storage/smgr.h>
#include <storage/lmgr.h>
#include <utils/inval.h>
#include <utils/mcxt.h>
#include <utils/syscache.h>
#include <commands/vacuum.h>
......@@ -1430,6 +1432,11 @@ _vc_updstats(Oid relid, int npages, int ntuples, bool hasindex)
/* XXX -- after write, should invalidate relcache in other backends */
WriteNoReleaseBuffer(buf); /* heap_endscan release scan' buffers ? */
/* invalidating system relations confuses the function cache
of pg_operator and pg_opclass */
if ( !IsSystemRelationName(pgcform->relname.data))
RelationInvalidateHeapTuple(rd, tup);
/* that's all, folks */
heap_endscan(sdesc);
heap_close(rd);
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.1.1.1 1996/07/09 06:21:32 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.2 1997/01/22 01:42:26 momjian Exp $
*
* NOTES
* Creator functions in POSTGRES 4.2 are generated automatically. Most of
......@@ -102,7 +102,8 @@ makeConst(Oid consttype,
Datum constvalue,
bool constisnull,
bool constbyval,
bool constisset)
bool constisset,
bool constiscast)
{
Const *cnst = makeNode(Const);
......@@ -112,6 +113,7 @@ makeConst(Oid consttype,
cnst->constisnull = constisnull;
cnst->constbyval = constbyval;
cnst->constisset = constisset;
cnst->constiscast = constiscast;
return cnst;
}
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.1.1.1 1996/07/09 06:21:38 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.2 1997/01/22 01:42:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -279,7 +279,8 @@ new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type)
(typedefault == (struct varlena *)NULL),
/* XXX this is bullshit */
false,
false /* not a set */);
false, /* not a set */
false);
temp3 = MakeTLE (makeResdom(attno,
atttype,
......
......@@ -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) =
......
......@@ -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)
{
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: makefuncs.h,v 1.2 1996/11/06 09:21:42 scrappy Exp $
* $Id: makefuncs.h,v 1.3 1997/01/22 01:43:41 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -41,6 +41,7 @@ extern Const *makeConst(Oid consttype,
Datum constvalue,
bool constisnull,
bool constbyval,
bool constisset);
bool constisset,
bool constiscast);
#endif /* MAKEFUNC_H */
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: primnodes.h,v 1.6 1996/11/04 07:18:21 scrappy Exp $
* $Id: primnodes.h,v 1.7 1997/01/22 01:43:44 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -175,6 +175,7 @@ typedef struct Const {
bool constisnull;
bool constbyval;
bool constisset;
bool constiscast;
} Const;
/* ----------------
......
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: catalog_utils.h,v 1.6 1996/12/11 03:18:12 bryanh Exp $
* $Id: catalog_utils.h,v 1.7 1997/01/22 01:44:02 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -46,6 +46,7 @@ extern Oid funcid_get_rettype(Oid funcid);
extern bool func_get_detail(char *funcname, int nargs, Oid *oid_array,
Oid *funcid, Oid *rettype, bool *retset, Oid **true_typeids);
extern Oid typeid_get_retinfunc(Oid type_id);
extern Oid typeid_get_retoutfunc(Oid type_id);
extern Oid typeid_get_relid(Oid type_id);
extern Oid get_typrelid(Type typ);
extern Oid get_typelem(Oid type_id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment