1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-26 12:21:12 +03:00

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.
This commit is contained in:
Tom Lane
2000-11-16 22:30:52 +00:00
parent cff23842a4
commit a933ee38bb
95 changed files with 2672 additions and 2314 deletions

View File

@ -7,12 +7,13 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.50 2000/10/05 19:11:34 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.51 2000/11/16 22:30:29 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "nodes/makefuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/tlist.h"
#include "parser/parsetree.h"
@ -555,20 +556,6 @@ AddNotQual(Query *parsetree, Node *qual)
}
/* Build a NULL constant expression of the given type */
static Node *
make_null(Oid type)
{
Const *c = makeNode(Const);
c->consttype = type;
c->constlen = get_typlen(type);
c->constvalue = PointerGetDatum(NULL);
c->constisnull = true;
c->constbyval = get_typbyval(type);
return (Node *) c;
}
/* Find a targetlist entry by resno */
static Node *
FindMatchingNew(List *tlist, int attno)
@ -656,7 +643,7 @@ ResolveNew_mutator(Node *node, ResolveNew_context *context)
else
{
/* Otherwise replace unmatched var with a null */
return make_null(var->vartype);
return (Node *) makeNullConst(var->vartype);
}
}
else
@ -796,7 +783,7 @@ HandleRIRAttributeRule_mutator(Node *node,
{ /* HACK: disallow SET variables */
*context->modified = TRUE;
*context->badsql = TRUE;
return make_null(var->vartype);
return (Node *) makeNullConst(var->vartype);
}
else
{
@ -813,7 +800,7 @@ HandleRIRAttributeRule_mutator(Node *node,
n = FindMatchingTLEntry(context->targetlist,
name_to_look_for);
if (n == NULL)
return make_null(var->vartype);
return (Node *) makeNullConst(var->vartype);
/* Make a copy of the tlist item to return */
n = copyObject(n);

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.40 2000/09/29 18:21:24 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.41 2000/11/16 22:30:29 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -35,21 +35,26 @@ RewriteGetRuleEventRel(char *rulename)
{
HeapTuple htup;
Oid eventrel;
char *result;
htup = SearchSysCacheTuple(RULENAME,
PointerGetDatum(rulename),
0, 0, 0);
htup = SearchSysCache(RULENAME,
PointerGetDatum(rulename),
0, 0, 0);
if (!HeapTupleIsValid(htup))
elog(ERROR, "Rule or view \"%s\" not found",
((strncmp(rulename, "_RET", 4) == 0) ? (rulename + 4) : rulename));
eventrel = ((Form_pg_rewrite) GETSTRUCT(htup))->ev_class;
htup = SearchSysCacheTuple(RELOID,
PointerGetDatum(eventrel),
0, 0, 0);
ReleaseSysCache(htup);
htup = SearchSysCache(RELOID,
PointerGetDatum(eventrel),
0, 0, 0);
if (!HeapTupleIsValid(htup))
elog(ERROR, "Relation %u not found", eventrel);
return NameStr(((Form_pg_class) GETSTRUCT(htup))->relname);
result = pstrdup(NameStr(((Form_pg_class) GETSTRUCT(htup))->relname));
ReleaseSysCache(htup);
return result;
}
/*
@ -75,9 +80,9 @@ RemoveRewriteRule(char *ruleName)
/*
* Find the tuple for the target rule.
*/
tuple = SearchSysCacheTupleCopy(RULENAME,
PointerGetDatum(ruleName),
0, 0, 0);
tuple = SearchSysCacheCopy(RULENAME,
PointerGetDatum(ruleName),
0, 0, 0);
/*
* complain if no rule with such name existed

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.44 2000/09/29 18:21:24 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.45 2000/11/16 22:30:29 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -18,19 +18,15 @@
#include "catalog/catname.h"
#include "catalog/indexing.h"
#include "rewrite/rewriteSupport.h"
#include "utils/catcache.h"
#include "utils/syscache.h"
int
bool
IsDefinedRewriteRule(char *ruleName)
{
HeapTuple tuple;
tuple = SearchSysCacheTuple(RULENAME,
return SearchSysCacheExists(RULENAME,
PointerGetDatum(ruleName),
0, 0, 0);
return HeapTupleIsValid(tuple);
}
/*
@ -59,10 +55,11 @@ SetRelationRuleStatus(Oid relationId, bool relHasRules,
* Find the tuple to update in pg_class, using syscache for the lookup.
*/
relationRelation = heap_openr(RelationRelationName, RowExclusiveLock);
tuple = SearchSysCacheTupleCopy(RELOID,
ObjectIdGetDatum(relationId),
0, 0, 0);
Assert(HeapTupleIsValid(tuple));
tuple = SearchSysCacheCopy(RELOID,
ObjectIdGetDatum(relationId),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "SetRelationRuleStatus: cache lookup failed for relation %u", relationId);
/* Do the update */
((Form_pg_class) GETSTRUCT(tuple))->relhasrules = relHasRules;