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 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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 @@ ...@@ -29,10 +29,12 @@
#include <catalog/pg_index.h> #include <catalog/pg_index.h>
#include <catalog/index.h> #include <catalog/index.h>
#include <catalog/catname.h> #include <catalog/catname.h>
#include <catalog/catalog.h>
#include <catalog/pg_class.h> #include <catalog/pg_class.h>
#include <catalog/pg_proc.h> #include <catalog/pg_proc.h>
#include <storage/smgr.h> #include <storage/smgr.h>
#include <storage/lmgr.h> #include <storage/lmgr.h>
#include <utils/inval.h>
#include <utils/mcxt.h> #include <utils/mcxt.h>
#include <utils/syscache.h> #include <utils/syscache.h>
#include <commands/vacuum.h> #include <commands/vacuum.h>
...@@ -1430,6 +1432,11 @@ _vc_updstats(Oid relid, int npages, int ntuples, bool hasindex) ...@@ -1430,6 +1432,11 @@ _vc_updstats(Oid relid, int npages, int ntuples, bool hasindex)
/* XXX -- after write, should invalidate relcache in other backends */ /* XXX -- after write, should invalidate relcache in other backends */
WriteNoReleaseBuffer(buf); /* heap_endscan release scan' buffers ? */ 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 */ /* that's all, folks */
heap_endscan(sdesc); heap_endscan(sdesc);
heap_close(rd); heap_close(rd);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* Creator functions in POSTGRES 4.2 are generated automatically. Most of * Creator functions in POSTGRES 4.2 are generated automatically. Most of
...@@ -102,7 +102,8 @@ makeConst(Oid consttype, ...@@ -102,7 +102,8 @@ makeConst(Oid consttype,
Datum constvalue, Datum constvalue,
bool constisnull, bool constisnull,
bool constbyval, bool constbyval,
bool constisset) bool constisset,
bool constiscast)
{ {
Const *cnst = makeNode(Const); Const *cnst = makeNode(Const);
...@@ -112,6 +113,7 @@ makeConst(Oid consttype, ...@@ -112,6 +113,7 @@ makeConst(Oid consttype,
cnst->constisnull = constisnull; cnst->constisnull = constisnull;
cnst->constbyval = constbyval; cnst->constbyval = constbyval;
cnst->constisset = constisset; cnst->constisset = constisset;
cnst->constiscast = constiscast;
return cnst; return cnst;
} }
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -279,7 +279,8 @@ new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type)
(typedefault == (struct varlena *)NULL), (typedefault == (struct varlena *)NULL),
/* XXX this is bullshit */ /* XXX this is bullshit */
false, false,
false /* not a set */); false, /* not a set */
false);
temp3 = MakeTLE (makeResdom(attno, temp3 = MakeTLE (makeResdom(attno,
atttype, atttype,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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, ...@@ -1288,7 +1288,8 @@ make_targetlist_expr(ParseState *pstate,
val, val,
false, false,
true, true,
true /* is set */); true, /* is set */
false);
} else { } else {
lnext(expr) = lnext(expr) =
makeConst(attrtype, makeConst(attrtype,
...@@ -1297,7 +1298,8 @@ make_targetlist_expr(ParseState *pstate, ...@@ -1297,7 +1298,8 @@ make_targetlist_expr(ParseState *pstate,
val,get_typelem(attrtype),-1), val,get_typelem(attrtype),-1),
false, false,
true /* Maybe correct-- 80% chance */, true /* Maybe correct-- 80% chance */,
false /* is not a set */); false, /* is not a set */
false);
} }
} else if((Typecast_ok) && (attrtype != type_id)){ } else if((Typecast_ok) && (attrtype != type_id)){
lnext(expr) = lnext(expr) =
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -1405,6 +1405,26 @@ typeid_get_retinfunc(Oid type_id)
return(infunc); 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 Oid
typeid_get_relid(Oid type_id) typeid_get_relid(Oid type_id)
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -367,10 +367,50 @@ make_op(char *opname, Node *ltree, Node *rtree)
left = NULL; left = NULL;
}else { }else {
char *outstr;
Oid infunc, outfunc;
Type newtype;
#define CONVERTABLE_TYPE(t) ( (t) == INT2OID || \
(t) == INT4OID || \
(t) == OIDOID || \
(t) == FLOAT4OID || \
(t) == FLOAT8OID)
/* binary operator */ /* binary operator */
ltypeId = (ltree==NULL) ? UNKNOWNOID : exprType(ltree); ltypeId = (ltree==NULL) ? UNKNOWNOID : exprType(ltree);
rtypeId = (rtree==NULL) ? UNKNOWNOID : exprType(rtree); 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); temp = oper(opname, ltypeId, rtypeId);
opform = (OperatorTupleForm) GETSTRUCT(temp); opform = (OperatorTupleForm) GETSTRUCT(temp);
left = make_operand(opname, ltree, ltypeId, opform->oprleft); left = make_operand(opname, ltree, ltypeId, opform->oprleft);
...@@ -654,7 +694,7 @@ make_const(Value *value) ...@@ -654,7 +694,7 @@ make_const(Value *value)
elog(NOTICE,"unknown type : %d\n", nodeTag(value)); elog(NOTICE,"unknown type : %d\n", nodeTag(value));
/* null const */ /* null const */
con = makeConst(0, 0, (Datum)NULL, TRUE, 0, FALSE); con = makeConst(0, 0, (Datum)NULL, true, false, false, false);
return con; return con;
} }
} }
...@@ -662,9 +702,10 @@ make_const(Value *value) ...@@ -662,9 +702,10 @@ make_const(Value *value)
con = makeConst(typeid(tp), con = makeConst(typeid(tp),
tlen(tp), tlen(tp),
val, val,
FALSE, false,
tbyval(tp), tbyval(tp),
FALSE); /* not a set */ false, /* not a set */
false);
return (con); return (con);
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -283,9 +283,10 @@ parser_typecast(Value *expr, TypeName *typename, int typlen)
adt = makeConst(typeid(tp), adt = makeConst(typeid(tp),
len, len,
(Datum)lcp , (Datum)lcp ,
0, false,
tbyvalue(tp), tbyvalue(tp),
0 /* not a set */); false, /* not a set */
true /* is cast */);
if (string_palloced) if (string_palloced)
pfree(const_string); pfree(const_string);
...@@ -365,8 +366,9 @@ parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen) ...@@ -365,8 +366,9 @@ parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen)
(Size) 0, (Size) 0,
(Datum) NULL, (Datum) NULL,
true, /* isnull */ true, /* isnull */
0 /* was omitted */, false, /* was omitted */
0 /* not a set */); false, /* not a set */
true /* is cast */);
return ((Node*) adt); return ((Node*) adt);
} }
...@@ -401,9 +403,10 @@ parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen) ...@@ -401,9 +403,10 @@ parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen)
adt = makeConst(typeid(tp), adt = makeConst(typeid(tp),
(Size)len, (Size)len,
(Datum)lcp, (Datum)lcp,
0, false,
0 /*was omitted*/, false, /*was omitted*/
0 /* not a set */); false, /* not a set */
true /* is cast */);
/* /*
printf("adt %s : %u %d %d\n",CString(expr),typeid(tp) , printf("adt %s : %u %d %d\n",CString(expr),typeid(tp) ,
len,cp); len,cp);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * 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, ...@@ -41,6 +41,7 @@ extern Const *makeConst(Oid consttype,
Datum constvalue, Datum constvalue,
bool constisnull, bool constisnull,
bool constbyval, bool constbyval,
bool constisset); bool constisset,
bool constiscast);
#endif /* MAKEFUNC_H */ #endif /* MAKEFUNC_H */
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * 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 { ...@@ -175,6 +175,7 @@ typedef struct Const {
bool constisnull; bool constisnull;
bool constbyval; bool constbyval;
bool constisset; bool constisset;
bool constiscast;
} Const; } Const;
/* ---------------- /* ----------------
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * 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); ...@@ -46,6 +46,7 @@ extern Oid funcid_get_rettype(Oid funcid);
extern bool func_get_detail(char *funcname, int nargs, Oid *oid_array, extern bool func_get_detail(char *funcname, int nargs, Oid *oid_array,
Oid *funcid, Oid *rettype, bool *retset, Oid **true_typeids); Oid *funcid, Oid *rettype, bool *retset, Oid **true_typeids);
extern Oid typeid_get_retinfunc(Oid type_id); 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 typeid_get_relid(Oid type_id);
extern Oid get_typrelid(Type typ); extern Oid get_typrelid(Type typ);
extern Oid get_typelem(Oid type_id); 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