aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/plancat.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-11-16 22:30:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-11-16 22:30:52 +0000
commita933ee38bbb8dffbc48a3363a94ff6f2a9f7964d (patch)
tree1c32737389b2530e7152dc2287161b36d9001e8c /src/backend/optimizer/util/plancat.c
parentcff23842a4c68301ddf34559c7af383bb5557054 (diff)
downloadpostgresql-a933ee38bbb8dffbc48a3363a94ff6f2a9f7964d.tar.gz
postgresql-a933ee38bbb8dffbc48a3363a94ff6f2a9f7964d.zip
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.
Diffstat (limited to 'src/backend/optimizer/util/plancat.c')
-rw-r--r--src/backend/optimizer/util/plancat.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index 0d32e82ed9a..055cd3788b9 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.61 2000/09/29 18:21:23 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.62 2000/11/16 22:30:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -48,9 +48,9 @@ relation_info(Oid relationObjectId,
HeapTuple relationTuple;
Form_pg_class relation;
- relationTuple = SearchSysCacheTuple(RELOID,
- ObjectIdGetDatum(relationObjectId),
- 0, 0, 0);
+ relationTuple = SearchSysCache(RELOID,
+ ObjectIdGetDatum(relationObjectId),
+ 0, 0, 0);
if (!HeapTupleIsValid(relationTuple))
elog(ERROR, "relation_info: Relation %u not found",
relationObjectId);
@@ -62,6 +62,7 @@ relation_info(Oid relationObjectId,
*hasindex = (relation->relhasindex) ? true : false;
*pages = relation->relpages;
*tuples = relation->reltuples;
+ ReleaseSysCache(relationTuple);
}
/*
@@ -100,9 +101,9 @@ find_secondary_indexes(Oid relationObjectId)
Oid relam;
uint16 amorderstrategy;
- indexTuple = SearchSysCacheTupleCopy(INDEXRELID,
- ObjectIdGetDatum(indexoid),
- 0, 0, 0);
+ indexTuple = SearchSysCache(INDEXRELID,
+ ObjectIdGetDatum(indexoid),
+ 0, 0, 0);
if (!HeapTupleIsValid(indexTuple))
elog(ERROR, "find_secondary_indexes: index %u not found",
indexoid);
@@ -162,20 +163,22 @@ find_secondary_indexes(Oid relationObjectId)
Form_pg_amop amop;
amopTuple =
- SearchSysCacheTuple(AMOPSTRATEGY,
- ObjectIdGetDatum(relam),
- ObjectIdGetDatum(index->indclass[i]),
- UInt16GetDatum(amorderstrategy),
- 0);
+ SearchSysCache(AMOPSTRATEGY,
+ ObjectIdGetDatum(relam),
+ ObjectIdGetDatum(index->indclass[i]),
+ UInt16GetDatum(amorderstrategy),
+ 0);
if (!HeapTupleIsValid(amopTuple))
elog(ERROR, "find_secondary_indexes: no amop %u %u %d",
- relam, index->indclass[i], (int) amorderstrategy);
+ relam, index->indclass[i],
+ (int) amorderstrategy);
amop = (Form_pg_amop) GETSTRUCT(amopTuple);
info->ordering[i] = amop->amopopr;
+ ReleaseSysCache(amopTuple);
}
}
- heap_freetuple(indexTuple);
+ ReleaseSysCache(indexTuple);
indexinfos = lcons(info, indexinfos);
}
@@ -315,13 +318,16 @@ find_inheritance_children(Oid inhparent)
bool
has_subclass(Oid relationId)
{
- HeapTuple tuple =
- SearchSysCacheTuple(RELOID,
- ObjectIdGetDatum(relationId),
- 0, 0, 0);
+ HeapTuple tuple;
+ bool result;
+ tuple = SearchSysCache(RELOID,
+ ObjectIdGetDatum(relationId),
+ 0, 0, 0);
if (!HeapTupleIsValid(tuple))
- elog(ERROR, "has_subclass: Relation %u not found",
- relationId);
- return ((Form_pg_class) GETSTRUCT(tuple))->relhassubclass;
+ elog(ERROR, "has_subclass: Relation %u not found", relationId);
+
+ result = ((Form_pg_class) GETSTRUCT(tuple))->relhassubclass;
+ ReleaseSysCache(tuple);
+ return result;
}