mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +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:
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.53 2000/05/30 04:24:27 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.54 2000/11/16 22:30:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -36,7 +36,7 @@ static void printtup_cleanup(DestReceiver *self);
|
||||
* getTypeOutAndElem -- get both typoutput and typelem for a type
|
||||
*
|
||||
* We used to fetch these with two separate function calls,
|
||||
* typtoout() and gettypelem(), which each called SearchSysCacheTuple.
|
||||
* typtoout() and gettypelem(), which each called SearchSysCache.
|
||||
* This way takes half the time.
|
||||
* ----------------
|
||||
*/
|
||||
@@ -44,25 +44,19 @@ int
|
||||
getTypeOutAndElem(Oid type, Oid *typOutput, Oid *typElem)
|
||||
{
|
||||
HeapTuple typeTuple;
|
||||
Form_pg_type pt;
|
||||
|
||||
typeTuple = SearchSysCacheTuple(TYPEOID,
|
||||
ObjectIdGetDatum(type),
|
||||
0, 0, 0);
|
||||
typeTuple = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(type),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(typeTuple))
|
||||
elog(ERROR, "getTypeOutAndElem: Cache lookup of type %u failed", type);
|
||||
pt = (Form_pg_type) GETSTRUCT(typeTuple);
|
||||
|
||||
if (HeapTupleIsValid(typeTuple))
|
||||
{
|
||||
Form_pg_type pt = (Form_pg_type) GETSTRUCT(typeTuple);
|
||||
|
||||
*typOutput = (Oid) pt->typoutput;
|
||||
*typElem = (Oid) pt->typelem;
|
||||
return OidIsValid(*typOutput);
|
||||
}
|
||||
|
||||
elog(ERROR, "getTypeOutAndElem: Cache lookup of type %u failed", type);
|
||||
|
||||
*typOutput = InvalidOid;
|
||||
*typElem = InvalidOid;
|
||||
return 0;
|
||||
*typOutput = pt->typoutput;
|
||||
*typElem = pt->typelem;
|
||||
ReleaseSysCache(typeTuple);
|
||||
return OidIsValid(*typOutput);
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.68 2000/11/08 22:09:53 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.69 2000/11/16 22:30:15 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* some of the executor utility code such as "ExecTypeFromTL" should be
|
||||
@@ -401,9 +401,9 @@ TupleDescInitEntry(TupleDesc desc,
|
||||
* -cim 6/14/90
|
||||
* ----------------
|
||||
*/
|
||||
tuple = SearchSysCacheTuple(TYPEOID,
|
||||
ObjectIdGetDatum(oidtypeid),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(oidtypeid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
{
|
||||
/* ----------------
|
||||
@@ -455,25 +455,18 @@ TupleDescInitEntry(TupleDesc desc,
|
||||
*/
|
||||
if (attisset)
|
||||
{
|
||||
Type t = typeidType(OIDOID);
|
||||
|
||||
att->attlen = typeLen(t);
|
||||
att->attbyval = typeByVal(t);
|
||||
att->attlen = sizeof(Oid);
|
||||
att->attbyval = true;
|
||||
att->attstorage = 'p';
|
||||
}
|
||||
else
|
||||
{
|
||||
att->attlen = typeForm->typlen;
|
||||
att->attbyval = typeForm->typbyval;
|
||||
/*
|
||||
* Default to the types storage
|
||||
*/
|
||||
#ifdef TUPLE_TOASTER_ACTIVE
|
||||
att->attstorage = typeForm->typstorage;
|
||||
#else
|
||||
att->attstorage = 'p';
|
||||
#endif
|
||||
}
|
||||
|
||||
ReleaseSysCache(tuple);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -496,12 +489,11 @@ TupleDescMakeSelfReference(TupleDesc desc,
|
||||
char *relname)
|
||||
{
|
||||
Form_pg_attribute att;
|
||||
Type t = typeidType(OIDOID);
|
||||
|
||||
att = desc->attrs[attnum - 1];
|
||||
att->atttypid = TypeShellMake(relname);
|
||||
att->attlen = typeLen(t);
|
||||
att->attbyval = typeByVal(t);
|
||||
att->attlen = sizeof(Oid);
|
||||
att->attbyval = true;
|
||||
att->attstorage = 'p';
|
||||
att->attnelems = 0;
|
||||
}
|
||||
@@ -580,7 +572,7 @@ BuildDescForRelation(List *schema, char *relname)
|
||||
}
|
||||
|
||||
if (!TupleDescInitEntry(desc, attnum, attname,
|
||||
typeTypeId(typenameType(typename)),
|
||||
typenameTypeId(typename),
|
||||
atttypmod, attdim, attisset))
|
||||
{
|
||||
/* ----------------
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/index/Attic/istrat.c,v 1.46 2000/07/14 22:17:30 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/index/Attic/istrat.c,v 1.47 2000/11/16 22:30:16 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -482,9 +482,9 @@ OperatorRelationFillScanKeyEntry(Relation operatorRelation,
|
||||
|
||||
if (cachesearch)
|
||||
{
|
||||
tuple = SearchSysCacheTuple(OPEROID,
|
||||
ObjectIdGetDatum(operatorObjectId),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(OPEROID,
|
||||
ObjectIdGetDatum(operatorObjectId),
|
||||
0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -505,24 +505,25 @@ OperatorRelationFillScanKeyEntry(Relation operatorRelation,
|
||||
{
|
||||
if (!cachesearch)
|
||||
heap_endscan(scan);
|
||||
elog(ERROR, "OperatorObjectIdFillScanKeyEntry: unknown operator %u",
|
||||
elog(ERROR, "OperatorRelationFillScanKeyEntry: unknown operator %u",
|
||||
operatorObjectId);
|
||||
}
|
||||
|
||||
entry->sk_flags = 0;
|
||||
entry->sk_procedure = ((Form_pg_operator) GETSTRUCT(tuple))->oprcode;
|
||||
fmgr_info(entry->sk_procedure, &entry->sk_func);
|
||||
entry->sk_nargs = entry->sk_func.fn_nargs;
|
||||
|
||||
if (!cachesearch)
|
||||
if (cachesearch)
|
||||
ReleaseSysCache(tuple);
|
||||
else
|
||||
heap_endscan(scan);
|
||||
|
||||
if (!RegProcedureIsValid(entry->sk_procedure))
|
||||
{
|
||||
elog(ERROR,
|
||||
"OperatorObjectIdFillScanKeyEntry: no procedure for operator %u",
|
||||
"OperatorRelationFillScanKeyEntry: no procedure for operator %u",
|
||||
operatorObjectId);
|
||||
}
|
||||
|
||||
fmgr_info(entry->sk_procedure, &entry->sk_func);
|
||||
entry->sk_nargs = entry->sk_func.fn_nargs;
|
||||
}
|
||||
|
||||
|
||||
@@ -547,16 +548,16 @@ IndexSupportInitialize(IndexStrategy indexStrategy,
|
||||
HeapTuple tuple;
|
||||
Form_pg_index iform;
|
||||
StrategyMap map;
|
||||
AttrNumber attributeNumber;
|
||||
int attributeIndex;
|
||||
AttrNumber attNumber;
|
||||
int attIndex;
|
||||
Oid operatorClassObjectId[INDEX_MAX_KEYS];
|
||||
bool cachesearch = (!IsBootstrapProcessingMode()) && IsCacheInitialized();
|
||||
|
||||
if (cachesearch)
|
||||
{
|
||||
tuple = SearchSysCacheTuple(INDEXRELID,
|
||||
ObjectIdGetDatum(indexObjectId),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(INDEXRELID,
|
||||
ObjectIdGetDatum(indexObjectId),
|
||||
0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -583,19 +584,23 @@ IndexSupportInitialize(IndexStrategy indexStrategy,
|
||||
* XXX note that the following assumes the INDEX tuple is well formed
|
||||
* and that the *key and *class are 0 terminated.
|
||||
*/
|
||||
for (attributeIndex = 0; attributeIndex < maxAttributeNumber; attributeIndex++)
|
||||
for (attIndex = 0; attIndex < maxAttributeNumber; attIndex++)
|
||||
{
|
||||
if (!OidIsValid(iform->indkey[attributeIndex]))
|
||||
if (!OidIsValid(iform->indkey[attIndex]))
|
||||
{
|
||||
if (attributeIndex == InvalidAttrNumber)
|
||||
if (attIndex == InvalidAttrNumber)
|
||||
elog(ERROR, "IndexSupportInitialize: no pg_index tuple");
|
||||
break;
|
||||
}
|
||||
|
||||
operatorClassObjectId[attributeIndex] = iform->indclass[attributeIndex];
|
||||
operatorClassObjectId[attIndex] = iform->indclass[attIndex];
|
||||
}
|
||||
|
||||
if (!cachesearch)
|
||||
if (cachesearch)
|
||||
{
|
||||
ReleaseSysCache(tuple);
|
||||
}
|
||||
else
|
||||
{
|
||||
heap_endscan(scan);
|
||||
heap_close(relation, AccessShareLock);
|
||||
@@ -614,20 +619,19 @@ IndexSupportInitialize(IndexStrategy indexStrategy,
|
||||
relation = heap_openr(AccessMethodProcedureRelationName,
|
||||
AccessShareLock);
|
||||
|
||||
for (attributeNumber = 1; attributeNumber <= maxAttributeNumber;
|
||||
attributeNumber++)
|
||||
for (attNumber = 1; attNumber <= maxAttributeNumber; attNumber++)
|
||||
{
|
||||
int16 support;
|
||||
Form_pg_amproc aform;
|
||||
RegProcedure *loc;
|
||||
|
||||
loc = &indexSupport[((attributeNumber - 1) * maxSupportNumber)];
|
||||
loc = &indexSupport[((attNumber - 1) * maxSupportNumber)];
|
||||
|
||||
for (support = 0; support < maxSupportNumber; ++support)
|
||||
loc[support] = InvalidOid;
|
||||
|
||||
entry[1].sk_argument =
|
||||
ObjectIdGetDatum(operatorClassObjectId[attributeNumber - 1]);
|
||||
ObjectIdGetDatum(operatorClassObjectId[attNumber - 1]);
|
||||
|
||||
scan = heap_beginscan(relation, false, SnapshotNow, 2, entry);
|
||||
|
||||
@@ -654,17 +658,16 @@ IndexSupportInitialize(IndexStrategy indexStrategy,
|
||||
relation = heap_openr(AccessMethodOperatorRelationName, AccessShareLock);
|
||||
operatorRelation = heap_openr(OperatorRelationName, AccessShareLock);
|
||||
|
||||
for (attributeNumber = maxAttributeNumber; attributeNumber > 0;
|
||||
attributeNumber--)
|
||||
for (attNumber = maxAttributeNumber; attNumber > 0; attNumber--)
|
||||
{
|
||||
StrategyNumber strategy;
|
||||
|
||||
entry[1].sk_argument =
|
||||
ObjectIdGetDatum(operatorClassObjectId[attributeNumber - 1]);
|
||||
ObjectIdGetDatum(operatorClassObjectId[attNumber - 1]);
|
||||
|
||||
map = IndexStrategyGetStrategyMap(indexStrategy,
|
||||
maxStrategyNumber,
|
||||
attributeNumber);
|
||||
attNumber);
|
||||
|
||||
for (strategy = 1; strategy <= maxStrategyNumber; strategy++)
|
||||
ScanKeyEntrySetIllegal(StrategyMapGetScanKeyEntry(map, strategy));
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.82 2000/11/10 00:33:08 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.83 2000/11/16 22:30:16 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Transaction aborts can now occur two ways:
|
||||
@@ -1112,6 +1112,7 @@ CommitTransaction(void)
|
||||
AtEOXact_nbtree();
|
||||
AtCommit_Cache();
|
||||
AtCommit_Locks();
|
||||
AtEOXact_CatCache(true);
|
||||
AtCommit_Memory();
|
||||
AtEOXact_Files();
|
||||
|
||||
@@ -1192,6 +1193,7 @@ AbortTransaction(void)
|
||||
AtEOXact_SPI();
|
||||
AtEOXact_nbtree();
|
||||
AtAbort_Cache();
|
||||
AtEOXact_CatCache(false);
|
||||
AtAbort_Memory();
|
||||
AtEOXact_Files();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user