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/commands/cluster.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/backend/commands/cluster.c') diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index c02bafc3227..5c263e4c26c 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.59 2000/11/08 22:09:57 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.60 2000/11/16 22:30:18 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -84,15 +84,16 @@ cluster(char *oldrelname, char *oldindexname) /* * Check that index is in fact an index on the given relation */ - tuple = SearchSysCacheTuple(INDEXRELID, - ObjectIdGetDatum(OIDOldIndex), - 0, 0, 0); + tuple = SearchSysCache(INDEXRELID, + ObjectIdGetDatum(OIDOldIndex), + 0, 0, 0); if (!HeapTupleIsValid(tuple)) elog(ERROR, "CLUSTER: no pg_index entry for index %u", OIDOldIndex); if (((Form_pg_index) GETSTRUCT(tuple))->indrelid != OIDOldHeap) elog(ERROR, "CLUSTER: \"%s\" is not an index for table \"%s\"", saveoldindexname, saveoldrelname); + ReleaseSysCache(tuple); /* Drop relcache refcnts, but do NOT give up the locks */ heap_close(OldHeap, NoLock); @@ -184,17 +185,17 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap, char *NewIndexName) * To do this I get the info from pg_index, and add a new index with * a temporary name. */ - Old_pg_index_Tuple = SearchSysCacheTupleCopy(INDEXRELID, - ObjectIdGetDatum(OIDOldIndex), - 0, 0, 0); + Old_pg_index_Tuple = SearchSysCache(INDEXRELID, + ObjectIdGetDatum(OIDOldIndex), + 0, 0, 0); Assert(Old_pg_index_Tuple); Old_pg_index_Form = (Form_pg_index) GETSTRUCT(Old_pg_index_Tuple); indexInfo = BuildIndexInfo(Old_pg_index_Tuple); - Old_pg_index_relation_Tuple = SearchSysCacheTupleCopy(RELOID, - ObjectIdGetDatum(OIDOldIndex), - 0, 0, 0); + Old_pg_index_relation_Tuple = SearchSysCache(RELOID, + ObjectIdGetDatum(OIDOldIndex), + 0, 0, 0); Assert(Old_pg_index_relation_Tuple); Old_pg_index_relation_Form = (Form_pg_class) GETSTRUCT(Old_pg_index_relation_Tuple); @@ -209,6 +210,9 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap, char *NewIndexName) setRelhasindex(OIDNewHeap, true); + ReleaseSysCache(Old_pg_index_Tuple); + ReleaseSysCache(Old_pg_index_relation_Tuple); + index_close(OldIndex); heap_close(NewHeap, NoLock); } -- cgit v1.2.3