Turns out it's easy to cache the fmgr function lookup

result, too ... another little bit of speed for SELECT.
This commit is contained in:
Tom Lane 1999-01-27 01:11:43 +00:00
parent 422221c90d
commit e27f8791f9

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.40 1999/01/27 00:36:22 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.41 1999/01/27 01:11:43 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -75,7 +75,7 @@ getTypeOutAndElem(Oid type, Oid* typOutput, Oid* typElem)
typedef struct { /* Per-attribute information */ typedef struct { /* Per-attribute information */
Oid typoutput; /* Oid for the attribute's type output fn */ Oid typoutput; /* Oid for the attribute's type output fn */
Oid typelem; /* typelem value to pass to the output fn */ Oid typelem; /* typelem value to pass to the output fn */
/* more soon... */ FmgrInfo finfo; /* Precomputed call info for typoutput */
} PrinttupAttrInfo; } PrinttupAttrInfo;
typedef struct { typedef struct {
@ -138,8 +138,9 @@ printtup_prepare_info(DR_printtup* myState, TupleDesc typeinfo, int numAttrs)
for (i = 0; i < numAttrs; i++) for (i = 0; i < numAttrs; i++)
{ {
PrinttupAttrInfo* thisState = myState->myinfo + i; PrinttupAttrInfo* thisState = myState->myinfo + i;
getTypeOutAndElem((Oid) typeinfo->attrs[i]->atttypid, if (getTypeOutAndElem((Oid) typeinfo->attrs[i]->atttypid,
&thisState->typoutput, &thisState->typelem); &thisState->typoutput, &thisState->typelem))
fmgr_info(thisState->typoutput, &thisState->finfo);
} }
} }
@ -200,15 +201,14 @@ printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver* self)
*/ */
for (i = 0; i < tuple->t_data->t_natts; ++i) for (i = 0; i < tuple->t_data->t_natts; ++i)
{ {
PrinttupAttrInfo* thisState = myState->myinfo + i;
attr = heap_getattr(tuple, i + 1, typeinfo, &isnull); attr = heap_getattr(tuple, i + 1, typeinfo, &isnull);
if (isnull) if (isnull)
continue; continue;
if (OidIsValid(myState->myinfo[i].typoutput)) if (OidIsValid(thisState->typoutput))
{ {
outputstr = fmgr(myState->myinfo[i].typoutput, outputstr = (char *) (*fmgr_faddr(&thisState->finfo))
attr, (attr, thisState->typelem, typeinfo->attrs[i]->atttypmod);
myState->myinfo[i].typelem,
typeinfo->attrs[i]->atttypmod);
#ifdef MULTIBYTE #ifdef MULTIBYTE
p = pg_server_to_client(outputstr, strlen(outputstr)); p = pg_server_to_client(outputstr, strlen(outputstr));
outputlen = strlen(p); outputlen = strlen(p);