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/utils/adt/sets.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'src/backend/utils/adt/sets.c') diff --git a/src/backend/utils/adt/sets.c b/src/backend/utils/adt/sets.c index 9a5f05134cd..6f64847dcab 100644 --- a/src/backend/utils/adt/sets.c +++ b/src/backend/utils/adt/sets.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.33 2000/08/24 03:29:06 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.34 2000/11/16 22:30:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -77,9 +77,11 @@ SetDefine(char *querystr, char *typename) */ CommandCounterIncrement(); - tup = SearchSysCacheTuple(PROCOID, - ObjectIdGetDatum(setoid), - 0, 0, 0); + procrel = heap_openr(ProcedureRelationName, RowExclusiveLock); + + tup = SearchSysCache(PROCOID, + ObjectIdGetDatum(setoid), + 0, 0, 0); if (!HeapTupleIsValid(tup)) elog(ERROR, "SetDefine: unable to define set %s", querystr); @@ -105,25 +107,15 @@ SetDefine(char *querystr, char *typename) replNull[i] = ' '; /* change the pg_proc tuple */ - procrel = heap_openr(ProcedureRelationName, RowExclusiveLock); + newtup = heap_modifytuple(tup, + procrel, + replValue, + replNull, + repl); - tup = SearchSysCacheTuple(PROCOID, - ObjectIdGetDatum(setoid), - 0, 0, 0); - if (HeapTupleIsValid(tup)) - { - newtup = heap_modifytuple(tup, - procrel, - replValue, - replNull, - repl); + heap_update(procrel, &newtup->t_self, newtup, NULL); - heap_update(procrel, &tup->t_self, newtup, NULL); - - setoid = newtup->t_data->t_oid; - } - else - elog(ERROR, "SetDefine: could not find new set oid tuple"); + setoid = newtup->t_data->t_oid; if (RelationGetForm(procrel)->relhasindex) { @@ -133,9 +125,13 @@ SetDefine(char *querystr, char *typename) CatalogIndexInsert(idescs, Num_pg_proc_indices, procrel, newtup); CatalogCloseIndices(Num_pg_proc_indices, idescs); } - heap_close(procrel, RowExclusiveLock); + heap_freetuple(newtup); } + ReleaseSysCache(tup); + + heap_close(procrel, RowExclusiveLock); + return setoid; } -- cgit v1.2.3