diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 8fa7afd129564a60bf422efcd4230852514ee7be..396dd80c08a0cb59bf81cbfda38f01add8c7b3fc 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -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 #include #include +#include #include #include #include #include +#include #include #include #include @@ -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); diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c index a461524e7adf5972d444a89eb4d8b3c21e9feb13..18894e8a41c78810ae0c4672cf86bb10cc873b42 100644 --- a/src/backend/nodes/makefuncs.c +++ b/src/backend/nodes/makefuncs.c @@ -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; } diff --git a/src/backend/optimizer/prep/preptlist.c b/src/backend/optimizer/prep/preptlist.c index fe1c2c92ba26ac64d32b6a0ae8ad17f34d942498..d57755ac064720ec1314a3410048994d7caf939f 100644 --- a/src/backend/optimizer/prep/preptlist.c +++ b/src/backend/optimizer/prep/preptlist.c @@ -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, diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 29eb7d3cf981ae3f04d92f556fc9275ced4cff07..463cc06c8222a1bfac033a6af5b097bd0562c44a 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -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) = diff --git a/src/backend/parser/catalog_utils.c b/src/backend/parser/catalog_utils.c index 87ba88b315df2d862ef0eb7d67b1283d1395d572..e444742ef3e6a7833db7b7e8c22b7e88ee0feb10 100644 --- a/src/backend/parser/catalog_utils.c +++ b/src/backend/parser/catalog_utils.c @@ -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) { diff --git a/src/backend/parser/parse_query.c b/src/backend/parser/parse_query.c index d3fffc1b24b69a3b91f03a4a49f37bfc675c60fc..372f758a140df273ff202dec777c1eabd26c6d28 100644 --- a/src/backend/parser/parse_query.c +++ b/src/backend/parser/parse_query.c @@ -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); } diff --git a/src/backend/parser/parser.c b/src/backend/parser/parser.c index 0b04666c179f169ce78782d9a698a2e9ec25a686..1babdb7e03ff62ae085a97d273216f6e8e5c331d 100644 --- a/src/backend/parser/parser.c +++ b/src/backend/parser/parser.c @@ -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); diff --git a/src/include/nodes/makefuncs.h b/src/include/nodes/makefuncs.h index 6bfec41bf8989b2c9dc8ebec37e93413fff235a9..a10182a33eeab9565c78093281096d5400d3f2a1 100644 --- a/src/include/nodes/makefuncs.h +++ b/src/include/nodes/makefuncs.h @@ -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 */ diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h index 828a9d595abed1f1609f9be6413684d6cafb96af..cd30f229c9c33f6a48f986ef062eeaa85c0f4661 100644 --- a/src/include/nodes/primnodes.h +++ b/src/include/nodes/primnodes.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; /* ---------------- diff --git a/src/include/parser/catalog_utils.h b/src/include/parser/catalog_utils.h index 5c7fe7f7531f9bb24b03b24ec18617d6ec66497f..df0d58ad18a323eacfbcbf48002ee8563d3180c5 100644 --- a/src/include/parser/catalog_utils.h +++ b/src/include/parser/catalog_utils.h @@ -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);