From a933ee38bbb8dffbc48a3363a94ff6f2a9f7964d Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 16 Nov 2000 22:30:52 +0000 Subject: Change SearchSysCache coding conventions so that a reference count is maintained for each cache entry. A cache entry will not be freed until the matching ReleaseSysCache call has been executed. This eliminates worries about cache entries getting dropped while still in use. See my posting to pg-hackers of even date for more info. --- src/backend/access/common/printtup.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'src/backend/access/common/printtup.c') diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c index 6fe0e9652c2..ccf3071b502 100644 --- a/src/backend/access/common/printtup.c +++ b/src/backend/access/common/printtup.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.53 2000/05/30 04:24:27 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.54 2000/11/16 22:30:15 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -36,7 +36,7 @@ static void printtup_cleanup(DestReceiver *self); * getTypeOutAndElem -- get both typoutput and typelem for a type * * We used to fetch these with two separate function calls, - * typtoout() and gettypelem(), which each called SearchSysCacheTuple. + * typtoout() and gettypelem(), which each called SearchSysCache. * This way takes half the time. * ---------------- */ @@ -44,25 +44,19 @@ int getTypeOutAndElem(Oid type, Oid *typOutput, Oid *typElem) { HeapTuple typeTuple; - - typeTuple = SearchSysCacheTuple(TYPEOID, - ObjectIdGetDatum(type), - 0, 0, 0); - - if (HeapTupleIsValid(typeTuple)) - { - Form_pg_type pt = (Form_pg_type) GETSTRUCT(typeTuple); - - *typOutput = (Oid) pt->typoutput; - *typElem = (Oid) pt->typelem; - return OidIsValid(*typOutput); - } - - elog(ERROR, "getTypeOutAndElem: Cache lookup of type %u failed", type); - - *typOutput = InvalidOid; - *typElem = InvalidOid; - return 0; + Form_pg_type pt; + + typeTuple = SearchSysCache(TYPEOID, + ObjectIdGetDatum(type), + 0, 0, 0); + if (!HeapTupleIsValid(typeTuple)) + elog(ERROR, "getTypeOutAndElem: Cache lookup of type %u failed", type); + pt = (Form_pg_type) GETSTRUCT(typeTuple); + + *typOutput = pt->typoutput; + *typElem = pt->typelem; + ReleaseSysCache(typeTuple); + return OidIsValid(*typOutput); } /* ---------------- -- cgit v1.2.3