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/gist/gist.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/backend/access/gist/gist.c') diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c index d7bfeb1287d..d8e9005e933 100644 --- a/src/backend/access/gist/gist.c +++ b/src/backend/access/gist/gist.c @@ -6,7 +6,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.64 2000/11/08 22:09:53 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.65 2000/11/16 22:30:15 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1140,6 +1140,7 @@ initGISTstate(GISTSTATE *giststate, Relation index) equal_proc; HeapTuple htup; Form_pg_index itupform; + Oid indexrelid; consistent_proc = index_getprocid(index, 1, GIST_CONSISTENT_PROC); union_proc = index_getprocid(index, 1, GIST_UNION_PROC); @@ -1157,32 +1158,32 @@ initGISTstate(GISTSTATE *giststate, Relation index) fmgr_info(equal_proc, &giststate->equalFn); /* see if key type is different from type of attribute being indexed */ - htup = SearchSysCacheTuple(INDEXRELID, - ObjectIdGetDatum(RelationGetRelid(index)), - 0, 0, 0); - itupform = (Form_pg_index) GETSTRUCT(htup); + htup = SearchSysCache(INDEXRELID, + ObjectIdGetDatum(RelationGetRelid(index)), + 0, 0, 0); if (!HeapTupleIsValid(htup)) elog(ERROR, "initGISTstate: index %u not found", RelationGetRelid(index)); + itupform = (Form_pg_index) GETSTRUCT(htup); giststate->haskeytype = itupform->indhaskeytype; + indexrelid = itupform->indexrelid; + ReleaseSysCache(htup); + if (giststate->haskeytype) { /* key type is different -- is it byval? */ - htup = SearchSysCacheTuple(ATTNUM, - ObjectIdGetDatum(itupform->indexrelid), - UInt16GetDatum(FirstOffsetNumber), - 0, 0); + htup = SearchSysCache(ATTNUM, + ObjectIdGetDatum(indexrelid), + UInt16GetDatum(FirstOffsetNumber), + 0, 0); if (!HeapTupleIsValid(htup)) - { elog(ERROR, "initGISTstate: no attribute tuple %u %d", - itupform->indexrelid, FirstOffsetNumber); - return; - } + indexrelid, FirstOffsetNumber); giststate->keytypbyval = (((Form_pg_attribute) htup)->attbyval); + ReleaseSysCache(htup); } else giststate->keytypbyval = FALSE; - return; } -- cgit v1.2.3