1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-14 18:42:34 +03:00

Clean up inefficient and just plain bad code in some hot-spot

cache access routines.
This commit is contained in:
Tom Lane
1999-05-29 01:45:21 +00:00
parent dc6d404959
commit ce2586dbc9
2 changed files with 241 additions and 189 deletions

View File

@ -7,14 +7,10 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.26 1999/05/10 00:46:07 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.27 1999/05/29 01:45:21 tgl Exp $
* *
* NOTES * NOTES
* Eventually, the index information should go through here, too. * Eventually, the index information should go through here, too.
*
* Most of these routines call SearchSysCacheStruct() and thus simply
* (1) allocate some space for the return struct and (2) call it.
*
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include <string.h> #include <string.h>
@ -45,13 +41,11 @@
bool bool
op_class(Oid oprno, int32 opclass, Oid amopid) op_class(Oid oprno, int32 opclass, Oid amopid)
{ {
FormData_pg_amop amoptup; if (HeapTupleIsValid(SearchSysCacheTuple(AMOPOPID,
if (SearchSysCacheStruct(AMOPOPID, (char *) &amoptup,
ObjectIdGetDatum(opclass), ObjectIdGetDatum(opclass),
ObjectIdGetDatum(oprno), ObjectIdGetDatum(oprno),
ObjectIdGetDatum(amopid), ObjectIdGetDatum(amopid),
0)) 0)))
return true; return true;
else else
return false; return false;
@ -69,13 +63,17 @@ op_class(Oid oprno, int32 opclass, Oid amopid)
char * char *
get_attname(Oid relid, AttrNumber attnum) get_attname(Oid relid, AttrNumber attnum)
{ {
FormData_pg_attribute att_tup; HeapTuple tp;
if (SearchSysCacheStruct(ATTNUM, (char *) &att_tup, tp = SearchSysCacheTuple(ATTNUM,
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
UInt16GetDatum(attnum), UInt16GetDatum(attnum),
0, 0)) 0, 0);
return pstrdup(att_tup.attname.data); if (HeapTupleIsValid(tp))
{
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
return pstrdup(att_tup->attname.data);
}
else else
return NULL; return NULL;
} }
@ -90,13 +88,17 @@ get_attname(Oid relid, AttrNumber attnum)
AttrNumber AttrNumber
get_attnum(Oid relid, char *attname) get_attnum(Oid relid, char *attname)
{ {
FormData_pg_attribute att_tup; HeapTuple tp;
if (SearchSysCacheStruct(ATTNAME, (char *) &att_tup, tp = SearchSysCacheTuple(ATTNAME,
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
PointerGetDatum(attname), PointerGetDatum(attname),
0, 0)) 0, 0);
return att_tup.attnum; if (HeapTupleIsValid(tp))
{
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
return att_tup->attnum;
}
else else
return InvalidAttrNumber; return InvalidAttrNumber;
} }
@ -111,15 +113,19 @@ get_attnum(Oid relid, char *attname)
Oid Oid
get_atttype(Oid relid, AttrNumber attnum) get_atttype(Oid relid, AttrNumber attnum)
{ {
Form_pg_attribute att_tup = (Form_pg_attribute) palloc(sizeof(*att_tup)); HeapTuple tp;
if (SearchSysCacheStruct(ATTNUM, (char *) att_tup, tp = SearchSysCacheTuple(ATTNUM,
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
UInt16GetDatum(attnum), UInt16GetDatum(attnum),
0, 0)) 0, 0);
if (HeapTupleIsValid(tp))
{
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
return att_tup->atttypid; return att_tup->atttypid;
}
else else
return (Oid) NULL; return InvalidOid;
} }
/* This routine uses the attname instead of the attnum because it /* This routine uses the attname instead of the attnum because it
@ -129,26 +135,19 @@ get_atttype(Oid relid, AttrNumber attnum)
bool bool
get_attisset(Oid relid, char *attname) get_attisset(Oid relid, char *attname)
{ {
HeapTuple tuple; HeapTuple tp;
AttrNumber attno;
Form_pg_attribute att_tup;
attno = get_attnum(relid, attname); tp = SearchSysCacheTuple(ATTNAME,
tuple = SearchSysCacheTuple(ATTNAME,
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
PointerGetDatum(attname), PointerGetDatum(attname),
0, 0); 0, 0);
if (!HeapTupleIsValid(tuple)) if (HeapTupleIsValid(tp))
elog(ERROR, "get_attisset: no attribute %s in relation %u",
attname, relid);
if (heap_attisnull(tuple, attno))
return false;
else
{ {
att_tup = (Form_pg_attribute) GETSTRUCT(tuple); Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
return att_tup->attisset; return att_tup->attisset;
} }
else
return false;
} }
/* /*
@ -161,13 +160,17 @@ get_attisset(Oid relid, char *attname)
int32 int32
get_atttypmod(Oid relid, AttrNumber attnum) get_atttypmod(Oid relid, AttrNumber attnum)
{ {
FormData_pg_attribute att_tup; HeapTuple tp;
if (SearchSysCacheStruct(ATTNUM, (char *) &att_tup, tp = SearchSysCacheTuple(ATTNUM,
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
Int16GetDatum(attnum), UInt16GetDatum(attnum),
0, 0)) 0, 0);
return att_tup.atttypmod; if (HeapTupleIsValid(tp))
{
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
return att_tup->atttypmod;
}
else else
return -1; return -1;
} }
@ -183,18 +186,22 @@ get_atttypmod(Oid relid, AttrNumber attnum)
* get_opcode - * get_opcode -
* *
* Returns the regproc id of the routine used to implement an * Returns the regproc id of the routine used to implement an
* operator given the operator uid. * operator given the operator oid.
* *
*/ */
RegProcedure RegProcedure
get_opcode(Oid opno) get_opcode(Oid opno)
{ {
FormData_pg_operator optup; HeapTuple tp;
if (SearchSysCacheStruct(OPROID, (char *) &optup, tp = SearchSysCacheTuple(OPROID,
ObjectIdGetDatum(opno), ObjectIdGetDatum(opno),
0, 0, 0)) 0, 0, 0);
return optup.oprcode; if (HeapTupleIsValid(tp))
{
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
return optup->oprcode;
}
else else
return (RegProcedure) NULL; return (RegProcedure) NULL;
} }
@ -203,25 +210,23 @@ get_opcode(Oid opno)
* get_opname - * get_opname -
* returns the name of the operator with the given opno * returns the name of the operator with the given opno
* *
* Note: return the struct so that it gets copied. * Note: returns a palloc'd copy of the string, or NULL if no such operator.
*/ */
char * char *
get_opname(Oid opno) get_opname(Oid opno)
{ {
FormData_pg_operator optup; HeapTuple tp;
if (SearchSysCacheStruct(OPROID, (char *) &optup, tp = SearchSysCacheTuple(OPROID,
ObjectIdGetDatum(opno), ObjectIdGetDatum(opno),
0, 0, 0)) 0, 0, 0);
return pstrdup(optup.oprname.data); if (HeapTupleIsValid(tp))
else
{ {
/* don't throw an error anymore; we want to continue... */ Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
#ifdef NOT_USED return pstrdup(optup->oprname.data);
elog(ERROR, "can't look up operator %u\n", opno);
#endif
return NULL;
} }
else
return NULL;
} }
/* /*
@ -234,22 +239,26 @@ get_opname(Oid opno)
bool bool
op_mergejoinable(Oid opno, Oid ltype, Oid rtype, Oid *leftOp, Oid *rightOp) op_mergejoinable(Oid opno, Oid ltype, Oid rtype, Oid *leftOp, Oid *rightOp)
{ {
FormData_pg_operator optup; HeapTuple tp;
if (SearchSysCacheStruct(OPROID, (char *) &optup, tp = SearchSysCacheTuple(OPROID,
ObjectIdGetDatum(opno), ObjectIdGetDatum(opno),
0, 0, 0) && 0, 0, 0);
optup.oprlsortop && if (HeapTupleIsValid(tp))
optup.oprrsortop &&
optup.oprleft == ltype &&
optup.oprright == rtype)
{ {
*leftOp = ObjectIdGetDatum(optup.oprlsortop); Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
*rightOp = ObjectIdGetDatum(optup.oprrsortop);
return TRUE; if (optup->oprlsortop &&
optup->oprrsortop &&
optup->oprleft == ltype &&
optup->oprright == rtype)
{
*leftOp = ObjectIdGetDatum(optup->oprlsortop);
*rightOp = ObjectIdGetDatum(optup->oprrsortop);
return true;
} }
else }
return FALSE; return false;
} }
/* /*
@ -262,38 +271,23 @@ op_mergejoinable(Oid opno, Oid ltype, Oid rtype, Oid *leftOp, Oid *rightOp)
Oid Oid
op_hashjoinable(Oid opno, Oid ltype, Oid rtype) op_hashjoinable(Oid opno, Oid ltype, Oid rtype)
{ {
FormData_pg_operator optup; HeapTuple tp;
if (SearchSysCacheStruct(OPROID, (char *) &optup, tp = SearchSysCacheTuple(OPROID,
ObjectIdGetDatum(opno), ObjectIdGetDatum(opno),
0, 0, 0) && 0, 0, 0);
optup.oprcanhash && if (HeapTupleIsValid(tp))
optup.oprleft == ltype && {
optup.oprright == rtype) Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
if (optup->oprcanhash &&
optup->oprleft == ltype &&
optup->oprright == rtype)
return opno; return opno;
else }
return InvalidOid; return InvalidOid;
} }
/*
* get_commutator -
*
* Returns the corresponding commutator of an operator.
*
*/
Oid
get_commutator(Oid opno)
{
FormData_pg_operator optup;
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0, 0, 0))
return optup.oprcom;
else
return (Oid) NULL;
}
HeapTuple HeapTuple
get_operator_tuple(Oid opno) get_operator_tuple(Oid opno)
{ {
@ -307,6 +301,29 @@ get_operator_tuple(Oid opno)
return (HeapTuple) NULL; return (HeapTuple) NULL;
} }
/*
* get_commutator -
*
* Returns the corresponding commutator of an operator.
*
*/
Oid
get_commutator(Oid opno)
{
HeapTuple tp;
tp = SearchSysCacheTuple(OPROID,
ObjectIdGetDatum(opno),
0, 0, 0);
if (HeapTupleIsValid(tp))
{
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
return optup->oprcom;
}
else
return InvalidOid;
}
/* /*
* get_negator - * get_negator -
* *
@ -316,14 +333,18 @@ get_operator_tuple(Oid opno)
Oid Oid
get_negator(Oid opno) get_negator(Oid opno)
{ {
FormData_pg_operator optup; HeapTuple tp;
if (SearchSysCacheStruct(OPROID, (char *) &optup, tp = SearchSysCacheTuple(OPROID,
ObjectIdGetDatum(opno), ObjectIdGetDatum(opno),
0, 0, 0)) 0, 0, 0);
return optup.oprnegate; if (HeapTupleIsValid(tp))
{
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
return optup->oprnegate;
}
else else
return (Oid) NULL; return InvalidOid;
} }
/* /*
@ -335,12 +356,16 @@ get_negator(Oid opno)
RegProcedure RegProcedure
get_oprrest(Oid opno) get_oprrest(Oid opno)
{ {
FormData_pg_operator optup; HeapTuple tp;
if (SearchSysCacheStruct(OPROID, (char *) &optup, tp = SearchSysCacheTuple(OPROID,
ObjectIdGetDatum(opno), ObjectIdGetDatum(opno),
0, 0, 0)) 0, 0, 0);
return optup.oprrest; if (HeapTupleIsValid(tp))
{
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
return optup->oprrest;
}
else else
return (RegProcedure) NULL; return (RegProcedure) NULL;
} }
@ -354,12 +379,16 @@ get_oprrest(Oid opno)
RegProcedure RegProcedure
get_oprjoin(Oid opno) get_oprjoin(Oid opno)
{ {
FormData_pg_operator optup; HeapTuple tp;
if (SearchSysCacheStruct(OPROID, (char *) &optup, tp = SearchSysCacheTuple(OPROID,
ObjectIdGetDatum(opno), ObjectIdGetDatum(opno),
0, 0, 0)) 0, 0, 0);
return optup.oprjoin; if (HeapTupleIsValid(tp))
{
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
return optup->oprjoin;
}
else else
return (RegProcedure) NULL; return (RegProcedure) NULL;
} }
@ -375,12 +404,16 @@ get_oprjoin(Oid opno)
int int
get_relnatts(Oid relid) get_relnatts(Oid relid)
{ {
FormData_pg_class reltup; HeapTuple tp;
if (SearchSysCacheStruct(RELOID, (char *) &reltup, tp = SearchSysCacheTuple(RELOID,
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
0, 0, 0)) 0, 0, 0);
return reltup.relnatts; if (HeapTupleIsValid(tp))
{
Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp);
return reltup->relnatts;
}
else else
return InvalidAttrNumber; return InvalidAttrNumber;
} }
@ -394,12 +427,16 @@ get_relnatts(Oid relid)
char * char *
get_rel_name(Oid relid) get_rel_name(Oid relid)
{ {
FormData_pg_class reltup; HeapTuple tp;
if ((SearchSysCacheStruct(RELOID, (char *) &reltup, tp = SearchSysCacheTuple(RELOID,
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
0, 0, 0))) 0, 0, 0);
return pstrdup(reltup.relname.data); if (HeapTupleIsValid(tp))
{
Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp);
return pstrdup(reltup->relname.data);
}
else else
return NULL; return NULL;
} }
@ -415,14 +452,18 @@ get_rel_name(Oid relid)
int16 int16
get_typlen(Oid typid) get_typlen(Oid typid)
{ {
FormData_pg_type typtup; HeapTuple tp;
if (SearchSysCacheStruct(TYPOID, (char *) &typtup, tp = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(typid), ObjectIdGetDatum(typid),
0, 0, 0)) 0, 0, 0);
return typtup.typlen; if (HeapTupleIsValid(tp))
{
Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);
return typtup->typlen;
}
else else
return (int16) NULL; return 0;
} }
/* /*
@ -435,33 +476,34 @@ get_typlen(Oid typid)
bool bool
get_typbyval(Oid typid) get_typbyval(Oid typid)
{ {
FormData_pg_type typtup; HeapTuple tp;
if (SearchSysCacheStruct(TYPOID, (char *) &typtup, tp = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(typid), ObjectIdGetDatum(typid),
0, 0, 0)) 0, 0, 0);
return (bool) typtup.typbyval; if (HeapTupleIsValid(tp))
{
Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);
return (bool) typtup->typbyval;
}
else else
return false; return false;
} }
/*
* get_typbyval -
*
* Given the type OID, determine whether the type is returned by value or
* not. Returns 1 if by value, 0 if by reference.
*
*/
#ifdef NOT_USED #ifdef NOT_USED
char char
get_typalign(Oid typid) get_typalign(Oid typid)
{ {
FormData_pg_type typtup; HeapTuple tp;
if (SearchSysCacheStruct(TYPOID, (char *) &typtup, tp = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(typid), ObjectIdGetDatum(typid),
0, 0, 0)) 0, 0, 0);
return typtup.typalign; if (HeapTupleIsValid(tp))
{
Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);
return typtup->typalign;
}
else else
return 'i'; return 'i';
} }
@ -494,12 +536,16 @@ get_typdefault(Oid typid)
char char
get_typtype(Oid typid) get_typtype(Oid typid)
{ {
FormData_pg_type typtup; HeapTuple tp;
if (SearchSysCacheStruct(TYPOID, (char *) &typtup, tp = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(typid), ObjectIdGetDatum(typid),
0, 0, 0)) 0, 0, 0);
return typtup.typtype; if (HeapTupleIsValid(tp))
{
Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);
return typtup->typtype;
}
else else
return '\0'; return '\0';
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.26 1999/05/25 22:42:15 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.27 1999/05/29 01:45:20 tgl Exp $
* *
* NOTES * NOTES
* These routines allow the parser/planner/executor to perform * These routines allow the parser/planner/executor to perform
@ -23,11 +23,7 @@
#include "access/htup.h" #include "access/htup.h"
#include "catalog/catname.h" #include "catalog/catname.h"
#include "utils/catcache.h" #include "utils/catcache.h"
#ifndef HAVE_MEMMOVE
#include <regex/utils.h>
#else
#include <string.h> #include <string.h>
#endif
/* ---------------- /* ----------------
@ -386,8 +382,7 @@ static struct cachedesc cacheinfo[] = {
NULL} NULL}
}; };
static struct catcache *SysCache[ static struct catcache *SysCache[lengthof(cacheinfo)];
lengthof(cacheinfo)];
static int32 SysCacheSize = lengthof(cacheinfo); static int32 SysCacheSize = lengthof(cacheinfo);
@ -547,7 +542,7 @@ SearchSysCacheStruct(int cacheId, /* cache selection code */
tp = SearchSysCacheTuple(cacheId, key1, key2, key3, key4); tp = SearchSysCacheTuple(cacheId, key1, key2, key3, key4);
if (!HeapTupleIsValid(tp)) if (!HeapTupleIsValid(tp))
return 0; return 0;
memmove(returnStruct, (char *) GETSTRUCT(tp), cacheinfo[cacheId].size); memcpy(returnStruct, (char *) GETSTRUCT(tp), cacheinfo[cacheId].size);
return 1; return 1;
} }
@ -555,9 +550,12 @@ SearchSysCacheStruct(int cacheId, /* cache selection code */
/* /*
* SearchSysCacheGetAttribute * SearchSysCacheGetAttribute
* Returns the attribute corresponding to 'attributeNumber' for * Returns the attribute corresponding to 'attributeNumber' for
* a given cached tuple. * a given cached tuple. This routine usually needs to be used for
* attributes that might be NULL or might be at a variable offset
* in the tuple.
* *
* XXX This re-opens a relation, so this is slower. * XXX This re-opens the relation, so this is slower than just pulling
* fixed-location fields out of the struct returned by SearchSysCacheTuple.
* *
* [callers all assume this returns a (struct varlena *). -ay 10/94] * [callers all assume this returns a (struct varlena *). -ay 10/94]
*/ */
@ -638,7 +636,7 @@ SearchSysCacheGetAttribute(int cacheId,
: attributeLength; /* fixed length */ : attributeLength; /* fixed length */
tmp = (char *) palloc(size); tmp = (char *) palloc(size);
memmove(tmp, (void *) attributeValue, size); memcpy(tmp, (void *) attributeValue, size);
returnValue = (void *) tmp; returnValue = (void *) tmp;
} }
@ -650,11 +648,8 @@ SearchSysCacheGetAttribute(int cacheId,
* TypeDefaultRetrieve * TypeDefaultRetrieve
* *
* Given a type OID, return the typdefault field associated with that * Given a type OID, return the typdefault field associated with that
* type. The typdefault is returned as the car of a dotted pair which * type. The result is a Datum, and points to palloc'd storage for
* is passed to TypeDefaultRetrieve by the calling routine. * non-pass-by-value types.
*
* Returns a fixnum for types which are passed by value and a ppreserve'd
* vectori for types which are not.
* *
* [identical to get_typdefault, expecting a (struct varlena *) as ret val. * [identical to get_typdefault, expecting a (struct varlena *) as ret val.
* some day, either of the functions should be removed -ay 10/94] * some day, either of the functions should be removed -ay 10/94]
@ -662,38 +657,24 @@ SearchSysCacheGetAttribute(int cacheId,
void * void *
TypeDefaultRetrieve(Oid typId) TypeDefaultRetrieve(Oid typId)
{ {
struct varlena *typDefault;
int32 dataSize;
HeapTuple typeTuple; HeapTuple typeTuple;
Form_pg_type type; Form_pg_type type;
int32 typByVal, int32 typByVal,
typLen; typLen;
struct varlena *typDefault;
int32 dataSize;
void *returnValue; void *returnValue;
typeTuple = SearchSysCacheTuple(TYPOID, /*
ObjectIdGetDatum(typId), * First, see if there is a non-null typdefault field (usually there isn't)
0, 0, 0); */
if (!HeapTupleIsValid(typeTuple))
{
#ifdef CACHEDEBUG
elog(DEBUG, "TypeDefaultRetrieve: Lookup in %s(%d) failed",
cacheinfo[TYPOID].name, TYPOID);
#endif /* defined(CACHEDEBUG) */
return NULL;
}
type = (Form_pg_type) GETSTRUCT(typeTuple);
typByVal = type->typbyval;
typLen = type->typlen;
typDefault = (struct varlena *) typDefault = (struct varlena *)
SearchSysCacheGetAttribute(TYPOID, SearchSysCacheGetAttribute(TYPOID,
Anum_pg_type_typdefault, Anum_pg_type_typdefault,
ObjectIdGetDatum(typId), ObjectIdGetDatum(typId),
0, 0, 0); 0, 0, 0);
if (typDefault == (struct varlena *) NULL) if (typDefault == NULL)
{ {
#ifdef CACHEDEBUG #ifdef CACHEDEBUG
elog(DEBUG, "TypeDefaultRetrieve: No extractable typdefault in %s(%d)", elog(DEBUG, "TypeDefaultRetrieve: No extractable typdefault in %s(%d)",
@ -704,26 +685,51 @@ TypeDefaultRetrieve(Oid typId)
dataSize = VARSIZE(typDefault) - VARHDRSZ; dataSize = VARSIZE(typDefault) - VARHDRSZ;
/*
* Need the type's length and byVal fields.
*
* XXX silly to repeat the syscache search that SearchSysCacheGetAttribute
* just did --- but at present this path isn't taken often enough to
* make it worth fixing.
*/
typeTuple = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(typId),
0, 0, 0);
if (!HeapTupleIsValid(typeTuple))
{
/* should never get here, really... */
#ifdef CACHEDEBUG
elog(DEBUG, "TypeDefaultRetrieve: Lookup in %s(%d) failed",
cacheinfo[TYPOID].name, TYPOID);
#endif /* defined(CACHEDEBUG) */
return NULL;
}
type = (Form_pg_type) GETSTRUCT(typeTuple);
typLen = type->typlen;
typByVal = type->typbyval;
if (typByVal) if (typByVal)
{ {
int8 i8; int8 i8;
int16 i16; int16 i16;
int32 i32; int32 i32 = 0;
if (dataSize == typLen) if (dataSize == typLen)
{ {
switch (typLen) switch (typLen)
{ {
case sizeof(int8): case sizeof(int8):
memmove((char *) &i8, VARDATA(typDefault), sizeof(int8)); memcpy((char *) &i8, VARDATA(typDefault), sizeof(int8));
i32 = i8; i32 = i8;
break; break;
case sizeof(int16): case sizeof(int16):
memmove((char *) &i16, VARDATA(typDefault), sizeof(int16)); memcpy((char *) &i16, VARDATA(typDefault), sizeof(int16));
i32 = i16; i32 = i16;
break; break;
case sizeof(int32): case sizeof(int32):
memmove((char *) &i32, VARDATA(typDefault), sizeof(int32)); memcpy((char *) &i32, VARDATA(typDefault), sizeof(int32));
break; break;
} }
returnValue = (void *) i32; returnValue = (void *) i32;
@ -738,7 +744,7 @@ TypeDefaultRetrieve(Oid typId)
else else
{ {
returnValue = (void *) palloc(VARSIZE(typDefault)); returnValue = (void *) palloc(VARSIZE(typDefault));
memmove((char *) returnValue, memcpy((char *) returnValue,
(char *) typDefault, (char *) typDefault,
(int) VARSIZE(typDefault)); (int) VARSIZE(typDefault));
} }