Avoid redundant SysCache searches in coerce_type, for another
few percent speedup in INSERT...
This commit is contained in:
parent
b325dab67a
commit
1bdd7c68c0
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.16 1999/05/25 16:10:15 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.17 1999/05/29 03:17:19 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -39,6 +39,7 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
|
||||
int32 atttypmod)
|
||||
{
|
||||
Node *result = NULL;
|
||||
Type targetType;
|
||||
Oid infunc;
|
||||
Datum val;
|
||||
|
||||
@ -79,10 +80,11 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
|
||||
Const *con = (Const *) node;
|
||||
|
||||
val = (Datum) textout((struct varlena *) con->constvalue);
|
||||
infunc = typeidInfunc(targetTypeId);
|
||||
targetType = typeidType(targetTypeId);
|
||||
infunc = typeInfunc(targetType);
|
||||
con = makeNode(Const);
|
||||
con->consttype = targetTypeId;
|
||||
con->constlen = typeLen(typeidType(targetTypeId));
|
||||
con->constlen = typeLen(targetType);
|
||||
|
||||
/*
|
||||
* Use "-1" for varchar() type. For char(), we need to pad
|
||||
@ -92,10 +94,10 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
|
||||
*/
|
||||
con->constvalue = (Datum) fmgr(infunc,
|
||||
val,
|
||||
typeidTypElem(targetTypeId),
|
||||
typeTypElem(targetType),
|
||||
(targetTypeId != BPCHAROID) ? -1 : atttypmod);
|
||||
con->constisnull = false;
|
||||
con->constbyval = typeByVal(typeidType(targetTypeId));
|
||||
con->constbyval = typeByVal(targetType);
|
||||
con->constisset = false;
|
||||
result = (Node *) con;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.40 1999/05/25 16:10:21 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.41 1999/05/29 03:17:20 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -241,7 +241,7 @@ MakeTargetEntryExpr(ParseState *pstate,
|
||||
Oid typelem;
|
||||
|
||||
if (arrayRef && !(((A_Indices *) lfirst(arrayRef))->lidx))
|
||||
typelem = typeidTypElem(attrtype);
|
||||
typelem = typeTypElem(typeidType(attrtype));
|
||||
else
|
||||
typelem = attrtype;
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.21 1999/05/25 16:10:22 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.22 1999/05/29 03:17:19 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -58,7 +58,7 @@ typeidTypeName(Oid id)
|
||||
return (typetuple->typname).data;
|
||||
}
|
||||
|
||||
/* return a Type structure, given an typid */
|
||||
/* return a Type structure, given a type id */
|
||||
Type
|
||||
typeidType(Oid id)
|
||||
{
|
||||
@ -180,7 +180,6 @@ typeidTypeRelid(Oid type_id)
|
||||
{
|
||||
HeapTuple typeTuple;
|
||||
Form_pg_type type;
|
||||
Oid infunc;
|
||||
|
||||
typeTuple = SearchSysCacheTuple(TYPOID,
|
||||
ObjectIdGetDatum(type_id),
|
||||
@ -189,8 +188,7 @@ typeidTypeRelid(Oid type_id)
|
||||
elog(ERROR, "typeidTypeRelid: Invalid type - oid = %u", type_id);
|
||||
|
||||
type = (Form_pg_type) GETSTRUCT(typeTuple);
|
||||
infunc = type->typrelid;
|
||||
return infunc;
|
||||
return type->typrelid;
|
||||
}
|
||||
|
||||
Oid
|
||||
@ -204,18 +202,13 @@ typeTypeRelid(Type typ)
|
||||
}
|
||||
|
||||
Oid
|
||||
typeidTypElem(Oid type_id)
|
||||
typeTypElem(Type typ)
|
||||
{
|
||||
HeapTuple typeTuple;
|
||||
Form_pg_type type;
|
||||
Form_pg_type typtup;
|
||||
|
||||
if (!(typeTuple = SearchSysCacheTuple(TYPOID,
|
||||
ObjectIdGetDatum(type_id),
|
||||
0, 0, 0)))
|
||||
elog(ERROR, "type id lookup of %u failed", type_id);
|
||||
type = (Form_pg_type) GETSTRUCT(typeTuple);
|
||||
typtup = (Form_pg_type) GETSTRUCT(typ);
|
||||
|
||||
return type->typelem;
|
||||
return typtup->typelem;
|
||||
}
|
||||
|
||||
/* Given the attribute type of an array return the attribute type of
|
||||
@ -247,21 +240,13 @@ GetArrayElementType(Oid typearray)
|
||||
return type_struct_array->typelem;
|
||||
}
|
||||
|
||||
/* Given a type id, returns the in-conversion function of the type */
|
||||
/* Given a type structure, return the in-conversion function of the type */
|
||||
Oid
|
||||
typeidInfunc(Oid type_id)
|
||||
typeInfunc(Type typ)
|
||||
{
|
||||
HeapTuple typeTuple;
|
||||
Form_pg_type type;
|
||||
Oid infunc;
|
||||
Form_pg_type typtup;
|
||||
|
||||
typeTuple = SearchSysCacheTuple(TYPOID,
|
||||
ObjectIdGetDatum(type_id),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(typeTuple))
|
||||
elog(ERROR, "typeidInfunc: Invalid type - oid = %u", type_id);
|
||||
typtup = (Form_pg_type) GETSTRUCT(typ);
|
||||
|
||||
type = (Form_pg_type) GETSTRUCT(typeTuple);
|
||||
infunc = type->typinput;
|
||||
return infunc;
|
||||
return typtup->typinput;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: parse_type.h,v 1.9 1998/10/08 18:30:39 momjian Exp $
|
||||
* $Id: parse_type.h,v 1.10 1999/05/29 03:17:19 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -29,8 +29,8 @@ extern char typeTypeFlag(Type t);
|
||||
extern char *stringTypeString(Type tp, char *string, int32 atttypmod);
|
||||
extern Oid typeidTypeRelid(Oid type_id);
|
||||
extern Oid typeTypeRelid(Type typ);
|
||||
extern Oid typeidTypElem(Oid type_id);
|
||||
extern Oid typeTypElem(Type typ);
|
||||
extern Oid GetArrayElementType(Oid typearray);
|
||||
extern Oid typeidInfunc(Oid type_id);
|
||||
extern Oid typeInfunc(Type typ);
|
||||
|
||||
#endif /* PARSE_TYPE_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user