1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

Ye-old pgindent run. Same 4-space tabs.

This commit is contained in:
Bruce Momjian
2000-04-12 17:17:23 +00:00
parent db4518729d
commit 52f77df613
434 changed files with 24799 additions and 21246 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.62 2000/02/21 03:36:49 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.63 2000/04/12 17:15:52 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -30,10 +30,10 @@
static void CatCacheRemoveCTup(CatCache *cache, Dlelem *e);
static Index CatalogCacheComputeHashIndex(struct catcache * cacheInP);
static Index CatalogCacheComputeTupleHashIndex(struct catcache * cacheInOutP,
Relation relation,
HeapTuple tuple);
Relation relation,
HeapTuple tuple);
static void CatalogCacheInitializeCache(struct catcache * cache,
Relation relation);
Relation relation);
static uint32 cc_hashname(NameData *n);
/* ----------------
@ -57,9 +57,10 @@ static uint32 cc_hashname(NameData *n);
#define CACHE6_elog(a,b,c,d,e,f,g)
#endif
static CatCache *Caches = NULL; /* head of list of caches */
static CatCache *Caches = NULL; /* head of list of caches */
GlobalMemory CacheCxt; /* context in which caches are allocated */
/* CacheCxt is global because relcache uses it too. */
@ -90,8 +91,8 @@ GetCCHashFunc(Oid keytype)
{
switch (keytype)
{
case BOOLOID:
case CHAROID:
case BOOLOID:
case CHAROID:
return (CCHashFunc) hashchar;
case NAMEOID:
return (CCHashFunc) cc_hashname;
@ -118,11 +119,12 @@ GetCCHashFunc(Oid keytype)
static uint32
cc_hashname(NameData *n)
{
/*
* We need our own variant of hashname because we want to accept
* null-terminated C strings as search values for name fields.
* So, we have to make sure the data is correctly padded before
* we compute the hash value.
* null-terminated C strings as search values for name fields. So, we
* have to make sure the data is correctly padded before we compute
* the hash value.
*/
NameData my_n;
@ -242,11 +244,14 @@ CatalogCacheInitializeCache(struct catcache * cache,
if (cache->cc_key[i] > 0)
{
Oid keytype = tupdesc->attrs[cache->cc_key[i] - 1]->atttypid;
Oid keytype = tupdesc->attrs[cache->cc_key[i] - 1]->atttypid;
cache->cc_hashfunc[i] = GetCCHashFunc(keytype);
/* If GetCCHashFunc liked the type, safe to index into eqproc[] */
/*
* If GetCCHashFunc liked the type, safe to index into
* eqproc[]
*/
cache->cc_skey[i].sk_procedure = EQPROC(keytype);
fmgr_info(cache->cc_skey[i].sk_procedure,
@ -314,19 +319,19 @@ CatalogCacheComputeHashIndex(struct catcache * cacheInP)
{
case 4:
hashIndex ^=
(*cacheInP->cc_hashfunc[3])(cacheInP->cc_skey[3].sk_argument) << 9;
(*cacheInP->cc_hashfunc[3]) (cacheInP->cc_skey[3].sk_argument) << 9;
/* FALLTHROUGH */
case 3:
hashIndex ^=
(*cacheInP->cc_hashfunc[2])(cacheInP->cc_skey[2].sk_argument) << 6;
(*cacheInP->cc_hashfunc[2]) (cacheInP->cc_skey[2].sk_argument) << 6;
/* FALLTHROUGH */
case 2:
hashIndex ^=
(*cacheInP->cc_hashfunc[1])(cacheInP->cc_skey[1].sk_argument) << 3;
(*cacheInP->cc_hashfunc[1]) (cacheInP->cc_skey[1].sk_argument) << 3;
/* FALLTHROUGH */
case 1:
hashIndex ^=
(*cacheInP->cc_hashfunc[0])(cacheInP->cc_skey[0].sk_argument);
(*cacheInP->cc_hashfunc[0]) (cacheInP->cc_skey[0].sk_argument);
break;
default:
elog(FATAL, "CCComputeHashIndex: %d cc_nkeys", cacheInP->cc_nkeys);
@ -612,10 +617,11 @@ ResetSystemCache()
void
SystemCacheRelationFlushed(Oid relId)
{
/*
* XXX Ideally we'd search the caches and just zap entries that actually
* refer to or come from the indicated relation. For now, we take the
* brute-force approach: just flush the caches entirely.
* XXX Ideally we'd search the caches and just zap entries that
* actually refer to or come from the indicated relation. For now, we
* take the brute-force approach: just flush the caches entirely.
*/
ResetSystemCache();
}
@ -688,6 +694,7 @@ InitSysCache(char *relname,
* ----------------
*/
{
/*
* We can only do this optimization because the number of hash
* buckets never changes. Without it, we call palloc() too much.
@ -782,8 +789,8 @@ InitSysCache(char *relname,
*
* This call searches for self-referencing information,
* which causes infinite recursion in the system catalog cache.
* This code short-circuits the normal index lookup for cache loads
* in those cases and replaces it with a heap scan.
* This code short-circuits the normal index lookup for cache loads
* in those cases and replaces it with a heap scan.
*
* cache should already be initailized
* --------------------------------
@ -791,40 +798,41 @@ InitSysCache(char *relname,
static HeapTuple
SearchSelfReferences(struct catcache * cache)
{
HeapTuple ntp;
Relation rel;
HeapTuple ntp;
Relation rel;
if (cache->id == INDEXRELID)
{
static Oid indexSelfOid = InvalidOid;
static HeapTuple indexSelfTuple = NULL;
static Oid indexSelfOid = InvalidOid;
static HeapTuple indexSelfTuple = NULL;
if (!OidIsValid(indexSelfOid))
{
ScanKeyData key;
HeapScanDesc sd;
ScanKeyData key;
HeapScanDesc sd;
/* Find oid of pg_index_indexrelid_index */
rel = heap_openr(RelationRelationName, AccessShareLock);
ScanKeyEntryInitialize(&key, 0, Anum_pg_class_relname,
F_NAMEEQ, PointerGetDatum(IndexRelidIndex));
F_NAMEEQ, PointerGetDatum(IndexRelidIndex));
sd = heap_beginscan(rel, false, SnapshotNow, 1, &key);
ntp = heap_getnext(sd, 0);
if (!HeapTupleIsValid(ntp))
elog(ERROR, "SearchSelfReferences: %s not found in %s",
IndexRelidIndex, RelationRelationName);
IndexRelidIndex, RelationRelationName);
indexSelfOid = ntp->t_data->t_oid;
heap_endscan(sd);
heap_close(rel, AccessShareLock);
}
/* Looking for something other than pg_index_indexrelid_index? */
if ((Oid)cache->cc_skey[0].sk_argument != indexSelfOid)
return (HeapTuple)0;
if ((Oid) cache->cc_skey[0].sk_argument != indexSelfOid)
return (HeapTuple) 0;
/* Do we need to load our private copy of the tuple? */
if (!HeapTupleIsValid(indexSelfTuple))
{
HeapScanDesc sd;
MemoryContext oldcxt;
HeapScanDesc sd;
MemoryContext oldcxt;
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
@ -844,16 +852,16 @@ SearchSelfReferences(struct catcache * cache)
else if (cache->id == OPEROID)
{
/* bootstrapping this requires preloading a range of rows. bjm */
static HeapTuple operatorSelfTuple[MAX_OIDCMP-MIN_OIDCMP+1];
Oid lookup_oid = (Oid)cache->cc_skey[0].sk_argument;
static HeapTuple operatorSelfTuple[MAX_OIDCMP - MIN_OIDCMP + 1];
Oid lookup_oid = (Oid) cache->cc_skey[0].sk_argument;
if (lookup_oid < MIN_OIDCMP || lookup_oid > MAX_OIDCMP)
return (HeapTuple)0;
return (HeapTuple) 0;
if (!HeapTupleIsValid(operatorSelfTuple[lookup_oid-MIN_OIDCMP]))
if (!HeapTupleIsValid(operatorSelfTuple[lookup_oid - MIN_OIDCMP]))
{
HeapScanDesc sd;
MemoryContext oldcxt;
HeapScanDesc sd;
MemoryContext oldcxt;
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
@ -863,15 +871,15 @@ SearchSelfReferences(struct catcache * cache)
if (!HeapTupleIsValid(ntp))
elog(ERROR, "SearchSelfReferences: tuple not found");
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
operatorSelfTuple[lookup_oid-MIN_OIDCMP] = heap_copytuple(ntp);
operatorSelfTuple[lookup_oid - MIN_OIDCMP] = heap_copytuple(ntp);
MemoryContextSwitchTo(oldcxt);
heap_endscan(sd);
heap_close(rel, AccessShareLock);
}
return operatorSelfTuple[lookup_oid-MIN_OIDCMP];
return operatorSelfTuple[lookup_oid - MIN_OIDCMP];
}
else
return (HeapTuple)0;
return (HeapTuple) 0;
}
@ -916,7 +924,7 @@ SearchSysCache(struct catcache * cache,
cache->cc_skey[3].sk_argument = v4;
/*
* resolve self referencing informtion
* resolve self referencing informtion
*/
if ((ntp = SearchSelfReferences(cache)))
return ntp;
@ -1052,12 +1060,13 @@ SearchSysCache(struct catcache * cache,
}
/* ----------
* Back to Cache context. If we got a tuple copy it
* into our context. wieck - 10/18/1996
* into our context. wieck - 10/18/1996
* And free the tuple that was allocated in the
* transaction's context. tgl - 02/03/2000
* ----------
*/
if (HeapTupleIsValid(indextp)) {
if (HeapTupleIsValid(indextp))
{
MemoryContextSwitchTo((MemoryContext) CacheCxt);
ntp = heap_copytuple(indextp);
MemoryContextSwitchTo(oldcxt);

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.29 2000/01/26 05:57:17 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.30 2000/04/12 17:15:53 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -126,6 +126,7 @@ init_fcache(Oid foid,
}
else
{
/*
* This is a hack. We assume here that any function returning a
* relation returns it by reference. This needs to be fixed.
@ -137,7 +138,7 @@ init_fcache(Oid foid,
retval->func_state = (char *) NULL;
retval->setArg = NULL;
retval->hasSetArg = false;
retval->oneResult = ! procedureStruct->proretset;
retval->oneResult = !procedureStruct->proretset;
retval->istrusted = procedureStruct->proistrusted;
/*
@ -148,7 +149,7 @@ init_fcache(Oid foid,
*/
if ((retval->language == SQLlanguageId) &&
retval->oneResult &&
! retval->typbyval)
!retval->typbyval)
{
Form_pg_class relationStruct;
HeapTuple relationTuple;

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.34 2000/01/31 04:35:52 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.35 2000/04/12 17:15:53 momjian Exp $
*
* Note - this code is real crufty...
*
@ -95,11 +95,13 @@ typedef InvalidationMessageData *InvalidationMessage;
* eaten by AtCommit_Cache() in CommitTransaction()
*/
static LocalInvalid InvalidForall = EmptyLocalInvalid;
/*
* head of invalidation linked list for the backend itself
* eaten by AtCommit_LocalCache() in CommandCounterIncrement()
*/
static LocalInvalid InvalidLocal = EmptyLocalInvalid;
/*
* head of rollback linked list for the backend itself
* eaten by AtAbort_Cache() in AbortTransaction()
@ -110,7 +112,7 @@ static LocalInvalid RollbackStack = EmptyLocalInvalid;
static InvalidationEntry InvalidationEntryAllocate(uint16 size);
static void LocalInvalidInvalidate(LocalInvalid invalid, void (*function) (), bool freemember);
static LocalInvalid LocalInvalidRegister(LocalInvalid invalid,
InvalidationEntry entry);
InvalidationEntry entry);
static void DiscardInvalidStack(LocalInvalid *invalid);
static void InvalidationMessageRegisterSharedInvalid(InvalidationMessage message);
@ -161,7 +163,7 @@ LocalInvalidRegister(LocalInvalid invalid,
* --------------------------------
*/
static void
LocalInvalidInvalidate(LocalInvalid invalid, void (*function) (), bool freemember)
LocalInvalidInvalidate(LocalInvalid invalid, void (*function) (), bool freemember)
{
InvalidationEntryData *entryDataP;
@ -187,12 +189,12 @@ LocalInvalidInvalidate(LocalInvalid invalid, void (*function) (), bool freemembe
static void
DiscardInvalidStack(LocalInvalid *invalid)
{
LocalInvalid locinv;
LocalInvalid locinv;
locinv = *invalid;
*invalid = EmptyLocalInvalid;
if (locinv)
LocalInvalidInvalidate(locinv, (void (*)()) NULL, true);
LocalInvalidInvalidate(locinv, (void (*) ()) NULL, true);
}
/* ----------------------------------------------------------------
@ -234,7 +236,7 @@ elog(DEBUG, "CacheIdImmediateRegisterSharedInvalid(%d, %d, [%d, %d])", \
*/
static LocalInvalid
CacheIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
Index cacheId, Index hashIndex, ItemPointer pointer)
Index cacheId, Index hashIndex, ItemPointer pointer)
{
InvalidationMessage message;
@ -286,13 +288,13 @@ CacheIdRegisterLocalInvalid(Index cacheId,
* ----------------
*/
InvalidForall = CacheIdRegisterSpecifiedLocalInvalid(InvalidForall,
cacheId, hashIndex, pointer);
cacheId, hashIndex, pointer);
/* ----------------
* Add message to InvalidLocal linked list.
* ----------------
*/
InvalidLocal = CacheIdRegisterSpecifiedLocalInvalid(InvalidLocal,
cacheId, hashIndex, pointer);
cacheId, hashIndex, pointer);
}
/* --------------------------------
@ -301,7 +303,7 @@ CacheIdRegisterLocalInvalid(Index cacheId,
*/
static void
CacheIdRegisterLocalRollback(Index cacheId, Index hashIndex,
ItemPointer pointer)
ItemPointer pointer)
{
/* ----------------
@ -315,7 +317,7 @@ CacheIdRegisterLocalRollback(Index cacheId, Index hashIndex,
* ----------------
*/
RollbackStack = CacheIdRegisterSpecifiedLocalInvalid(
RollbackStack, cacheId, hashIndex, pointer);
RollbackStack, cacheId, hashIndex, pointer);
}
/* --------------------------------
@ -324,7 +326,7 @@ CacheIdRegisterLocalRollback(Index cacheId, Index hashIndex,
*/
static void
CacheIdImmediateRegisterSharedInvalid(Index cacheId, Index hashIndex,
ItemPointer pointer)
ItemPointer pointer)
{
InvalidationMessage message;
@ -361,7 +363,7 @@ CacheIdImmediateRegisterSharedInvalid(Index cacheId, Index hashIndex,
*/
static LocalInvalid
RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
Oid relationId, Oid objectId)
Oid relationId, Oid objectId)
{
InvalidationMessage message;
@ -415,13 +417,13 @@ RelationIdRegisterLocalInvalid(Oid relationId, Oid objectId)
* ----------------
*/
InvalidForall = RelationIdRegisterSpecifiedLocalInvalid(InvalidForall,
relationId, objectId);
relationId, objectId);
/* ----------------
* Add message to InvalidLocal linked list.
* ----------------
*/
InvalidLocal = RelationIdRegisterSpecifiedLocalInvalid(InvalidLocal,
relationId, objectId);
relationId, objectId);
}
/* --------------------------------
@ -446,7 +448,7 @@ RelationIdRegisterLocalRollback(Oid relationId, Oid objectId)
* ----------------
*/
RollbackStack = RelationIdRegisterSpecifiedLocalInvalid(
RollbackStack, relationId, objectId);
RollbackStack, relationId, objectId);
}
/* --------------------------------
@ -643,16 +645,16 @@ InvalidationMessageCacheInvalidate(InvalidationMessage message)
InvalidationMessageCacheInvalidate_DEBUG1;
CacheIdInvalidate(message->any.catalog.cacheId,
message->any.catalog.hashIndex,
&message->any.catalog.pointerData);
message->any.catalog.hashIndex,
&message->any.catalog.pointerData);
break;
case 'r': /* cached relation descriptor */
InvalidationMessageCacheInvalidate_DEBUG2;
CacheIdInvalidate(message->any.relation.relationId,
message->any.relation.objectId,
(ItemPointer) NULL);
message->any.relation.objectId,
(ItemPointer) NULL);
break;
default:
@ -753,14 +755,14 @@ RegisterInvalid(bool send)
{
DiscardInvalidStack(&RollbackStack);
invalid = InvalidForall;
InvalidForall = EmptyLocalInvalid; /* clear InvalidForall */
InvalidForall = EmptyLocalInvalid; /* clear InvalidForall */
LocalInvalidInvalidate(invalid, InvalidationMessageRegisterSharedInvalid, true);
}
else
{
DiscardInvalidStack(&InvalidForall);
invalid = RollbackStack;
RollbackStack = EmptyLocalInvalid; /* clear RollbackStack */
RollbackStack = EmptyLocalInvalid; /* clear RollbackStack */
LocalInvalidInvalidate(invalid, InvalidationMessageCacheInvalidate, true);
}
@ -794,14 +796,15 @@ ImmediateLocalInvalidation(bool send)
if (send)
{
invalid = InvalidLocal;
InvalidLocal = EmptyLocalInvalid; /* clear InvalidLocal */
InvalidLocal = EmptyLocalInvalid; /* clear InvalidLocal */
LocalInvalidInvalidate(invalid, InvalidationMessageCacheInvalidate, true);
}
else
{
/*
* This may be used for rollback to a savepoint.
* Don't clear InvalidForall and RollbackStack here.
* This may be used for rollback to a savepoint. Don't clear
* InvalidForall and RollbackStack here.
*/
DiscardInvalidStack(&InvalidLocal);
invalid = RollbackStack;
@ -813,8 +816,8 @@ ImmediateLocalInvalidation(bool send)
/*
* InvokeHeapTupleInvalidation
* Invoke functions for the tuple which register invalidation
* of catalog/relation cache.
* Note:
* of catalog/relation cache.
* Note:
* Assumes object id is valid.
* Assumes tuple is valid.
*/
@ -831,9 +834,9 @@ elog(DEBUG, "%s(%s, [%d,%d])", \
static void
InvokeHeapTupleInvalidation(Relation relation, HeapTuple tuple,
void (*CacheIdRegisterFunc)(),
void (*RelationIdRegisterFunc)(),
const char *funcname)
void (*CacheIdRegisterFunc) (),
void (*RelationIdRegisterFunc) (),
const char *funcname)
{
/* ----------------
* sanity checks
@ -857,13 +860,13 @@ InvokeHeapTupleInvalidation(Relation relation, HeapTuple tuple,
*/
InvokeHeapTupleInvalidation_DEBUG1;
RelationInvalidateCatalogCacheTuple(relation, tuple,
CacheIdRegisterFunc);
RelationInvalidateCatalogCacheTuple(relation, tuple,
CacheIdRegisterFunc);
RelationInvalidateRelationCache(relation, tuple,
RelationIdRegisterFunc);
RelationIdRegisterFunc);
}
/*
* RelationInvalidateHeapTuple
* Causes the given tuple in a relation to be invalidated.
@ -871,10 +874,10 @@ InvokeHeapTupleInvalidation(Relation relation, HeapTuple tuple,
void
RelationInvalidateHeapTuple(Relation relation, HeapTuple tuple)
{
InvokeHeapTupleInvalidation(relation, tuple,
CacheIdRegisterLocalInvalid,
RelationIdRegisterLocalInvalid,
"RelationInvalidateHeapTuple");
InvokeHeapTupleInvalidation(relation, tuple,
CacheIdRegisterLocalInvalid,
RelationIdRegisterLocalInvalid,
"RelationInvalidateHeapTuple");
}
/*
@ -886,9 +889,9 @@ void
RelationMark4RollbackHeapTuple(Relation relation, HeapTuple tuple)
{
InvokeHeapTupleInvalidation(relation, tuple,
CacheIdRegisterLocalRollback,
RelationIdRegisterLocalRollback,
"RelationMark4RollbackHeapTuple");
CacheIdRegisterLocalRollback,
RelationIdRegisterLocalRollback,
"RelationMark4RollbackHeapTuple");
}
/*
@ -900,9 +903,9 @@ void
ImmediateInvalidateSharedHeapTuple(Relation relation, HeapTuple tuple)
{
InvokeHeapTupleInvalidation(relation, tuple,
CacheIdImmediateRegisterSharedInvalid,
RelationIdImmediateRegisterSharedInvalid,
"ImmediateInvalidateSharedHeapTuple");
CacheIdImmediateRegisterSharedInvalid,
RelationIdImmediateRegisterSharedInvalid,
"ImmediateInvalidateSharedHeapTuple");
}
/*
@ -912,8 +915,8 @@ ImmediateInvalidateSharedHeapTuple(Relation relation, HeapTuple tuple)
* This is needed for smgrunlink()/smgrtruncate().
* Those functions unlink/truncate the base file immediately
* and couldn't be rollbacked in case of abort/crash.
* So relation cache invalidation must be registerd immediately.
* Note:
* So relation cache invalidation must be registerd immediately.
* Note:
* Assumes Relation is valid.
*/
void
@ -933,10 +936,10 @@ ImmediateSharedRelationCacheInvalidate(Relation relation)
* ----------------
*/
#ifdef INVALIDDEBUG
elog(DEBUG, "ImmediateSharedRelationCacheInvalidate(%s)", \
RelationGetPhysicalRelationName(relation));
elog(DEBUG, "ImmediateSharedRelationCacheInvalidate(%s)", \
RelationGetPhysicalRelationName(relation));
#endif /* defined(INVALIDDEBUG) */
RelationIdImmediateRegisterSharedInvalid(
RelOid_pg_class, RelationGetRelid(relation));
RelOid_pg_class, RelationGetRelid(relation));
}

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.40 2000/02/16 01:00:23 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.41 2000/04/12 17:15:53 momjian Exp $
*
* NOTES
* Eventually, the index information should go through here, too.
@ -64,6 +64,7 @@ get_attname(Oid relid, AttrNumber attnum)
if (HeapTupleIsValid(tp))
{
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
return pstrdup(NameStr(att_tup->attname));
}
else
@ -89,6 +90,7 @@ get_attnum(Oid relid, char *attname)
if (HeapTupleIsValid(tp))
{
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
return att_tup->attnum;
}
else
@ -114,6 +116,7 @@ get_atttype(Oid relid, AttrNumber attnum)
if (HeapTupleIsValid(tp))
{
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
return att_tup->atttypid;
}
else
@ -136,6 +139,7 @@ get_attisset(Oid relid, char *attname)
if (HeapTupleIsValid(tp))
{
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
return att_tup->attisset;
}
else
@ -161,6 +165,7 @@ get_atttypmod(Oid relid, AttrNumber attnum)
if (HeapTupleIsValid(tp))
{
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
return att_tup->atttypmod;
}
else
@ -206,8 +211,8 @@ get_attdisbursion(Oid relid, AttrNumber attnum, double min_estimate)
/*
* Special-case boolean columns: the disbursion of a boolean is highly
* unlikely to be anywhere near 1/numtuples, instead it's probably more
* like 0.5.
* unlikely to be anywhere near 1/numtuples, instead it's probably
* more like 0.5.
*
* Are there any other cases we should wire in special estimates for?
*/
@ -215,8 +220,8 @@ get_attdisbursion(Oid relid, AttrNumber attnum, double min_estimate)
return 0.5;
/*
* Disbursion is either 0 (no data available) or -1 (disbursion
* is 1/numtuples). Either way, we need the relation size.
* Disbursion is either 0 (no data available) or -1 (disbursion is
* 1/numtuples). Either way, we need the relation size.
*/
atp = SearchSysCacheTuple(RELOID,
@ -246,10 +251,9 @@ get_attdisbursion(Oid relid, AttrNumber attnum, double min_estimate)
return 1.0 / (double) ntuples;
/*
* VACUUM ANALYZE has not been run for this table.
* Produce an estimate = 1/numtuples. This may produce
* unreasonably small estimates for large tables, so limit
* the estimate to no less than min_estimate.
* VACUUM ANALYZE has not been run for this table. Produce an estimate
* = 1/numtuples. This may produce unreasonably small estimates for
* large tables, so limit the estimate to no less than min_estimate.
*/
disbursion = 1.0 / (double) ntuples;
if (disbursion < min_estimate)
@ -283,6 +287,7 @@ get_opcode(Oid opno)
if (HeapTupleIsValid(tp))
{
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
return optup->oprcode;
}
else
@ -306,6 +311,7 @@ get_opname(Oid opno)
if (HeapTupleIsValid(tp))
{
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
return pstrdup(NameStr(optup->oprname));
}
else
@ -401,6 +407,7 @@ get_commutator(Oid opno)
if (HeapTupleIsValid(tp))
{
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
return optup->oprcom;
}
else
@ -424,6 +431,7 @@ get_negator(Oid opno)
if (HeapTupleIsValid(tp))
{
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
return optup->oprnegate;
}
else
@ -447,6 +455,7 @@ get_oprrest(Oid opno)
if (HeapTupleIsValid(tp))
{
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
return optup->oprrest;
}
else
@ -470,6 +479,7 @@ get_oprjoin(Oid opno)
if (HeapTupleIsValid(tp))
{
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);
return optup->oprjoin;
}
else
@ -520,6 +530,7 @@ get_relnatts(Oid relid)
if (HeapTupleIsValid(tp))
{
Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp);
return reltup->relnatts;
}
else
@ -543,6 +554,7 @@ get_rel_name(Oid relid)
if (HeapTupleIsValid(tp))
{
Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp);
return pstrdup(NameStr(reltup->relname));
}
else
@ -568,6 +580,7 @@ get_typlen(Oid typid)
if (HeapTupleIsValid(tp))
{
Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);
return typtup->typlen;
}
else
@ -592,6 +605,7 @@ get_typbyval(Oid typid)
if (HeapTupleIsValid(tp))
{
Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);
return (bool) typtup->typbyval;
}
else
@ -610,6 +624,7 @@ get_typalign(Oid typid)
if (HeapTupleIsValid(tp))
{
Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);
return typtup->typalign;
}
else
@ -649,11 +664,12 @@ get_typdefault(Oid typid)
type = (Form_pg_type) GETSTRUCT(typeTuple);
/*
* First, see if there is a non-null typdefault field (usually there isn't)
* First, see if there is a non-null typdefault field (usually there
* isn't)
*/
typDefault = (struct varlena *) SysCacheGetAttr(TYPEOID,
typeTuple,
Anum_pg_type_typdefault,
Anum_pg_type_typdefault,
&isNull);
if (isNull)
@ -743,6 +759,7 @@ get_typtype(Oid typid)
if (HeapTupleIsValid(tp))
{
Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);
return typtup->typtype;
}
else

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.94 2000/03/31 19:39:22 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.95 2000/04/12 17:15:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -80,8 +80,8 @@ static FormData_pg_attribute Desc_pg_log[Natts_pg_log] = {Schema_pg_log};
* thus there are two hash tables for referencing them.
* ----------------
*/
static HTAB *RelationNameCache;
static HTAB *RelationIdCache;
static HTAB *RelationNameCache;
static HTAB *RelationIdCache;
/*
* newlyCreatedRelns -
@ -204,20 +204,20 @@ do { \
static void RelationClearRelation(Relation relation, bool rebuildIt);
static void RelationFlushRelation(Relation *relationPtr,
int skipLocalRelations);
int skipLocalRelations);
static Relation RelationNameCacheGetRelation(const char *relationName);
static void RelationCacheAbortWalker(Relation *relationPtr, int dummy);
static void init_irels(void);
static void write_irels(void);
static void formrdesc(char *relationName, u_int natts,
FormData_pg_attribute *att);
FormData_pg_attribute *att);
static HeapTuple ScanPgRelation(RelationBuildDescInfo buildinfo);
static HeapTuple scan_pg_rel_seq(RelationBuildDescInfo buildinfo);
static HeapTuple scan_pg_rel_ind(RelationBuildDescInfo buildinfo);
static Relation AllocateRelationDesc(Relation relation, u_int natts,
Form_pg_class relp);
Form_pg_class relp);
static void RelationBuildTupleDesc(RelationBuildDescInfo buildinfo,
Relation relation, u_int natts);
static void build_tupdesc_seq(RelationBuildDescInfo buildinfo,
@ -225,12 +225,13 @@ static void build_tupdesc_seq(RelationBuildDescInfo buildinfo,
static void build_tupdesc_ind(RelationBuildDescInfo buildinfo,
Relation relation, u_int natts);
static Relation RelationBuildDesc(RelationBuildDescInfo buildinfo,
Relation oldrelation);
Relation oldrelation);
static void IndexedAccessMethodInitialize(Relation relation);
static void AttrDefaultFetch(Relation relation);
static void RelCheckFetch(Relation relation);
static bool criticalRelcacheBuild = false;
static bool criticalRelcacheBuild = false;
/* ----------------------------------------------------------------
* RelationIdGetRelation() and RelationNameGetRelation()
* support functions
@ -350,7 +351,7 @@ scan_pg_rel_ind(RelationBuildDescInfo buildinfo)
default:
elog(ERROR, "ScanPgRelation: bad buildinfo");
return_tuple = NULL; /* keep compiler quiet */
return_tuple = NULL;/* keep compiler quiet */
}
heap_close(pg_class_desc, AccessShareLock);
@ -483,7 +484,7 @@ build_tupdesc_seq(RelationBuildDescInfo buildinfo,
int need;
TupleConstr *constr = (TupleConstr *) palloc(sizeof(TupleConstr));
AttrDefault *attrdef = NULL;
int ndef = 0;
int ndef = 0;
constr->has_not_null = false;
/* ----------------
@ -531,7 +532,7 @@ build_tupdesc_seq(RelationBuildDescInfo buildinfo,
if (attrdef == NULL)
{
attrdef = (AttrDefault *) palloc(relation->rd_rel->relnatts *
sizeof(AttrDefault));
sizeof(AttrDefault));
MemSet(attrdef, 0,
relation->rd_rel->relnatts * sizeof(AttrDefault));
}
@ -569,9 +570,11 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo,
AttrDefault *attrdef = NULL;
int ndef = 0;
int i;
#ifdef _DROP_COLUMN_HACK__
bool columnDropped;
#endif /* _DROP_COLUMN_HACK__ */
bool columnDropped;
#endif /* _DROP_COLUMN_HACK__ */
constr->has_not_null = false;
@ -581,7 +584,7 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo,
{
#ifdef _DROP_COLUMN_HACK__
columnDropped = false;
#endif /* _DROP_COLUMN_HACK__ */
#endif /* _DROP_COLUMN_HACK__ */
atttup = (HeapTuple) AttributeRelidNumIndexScan(attrel,
RelationGetRelid(relation), i);
@ -589,15 +592,15 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo,
#ifdef _DROP_COLUMN_HACK__
{
atttup = (HeapTuple) AttributeRelidNumIndexScan(attrel,
RelationGetRelid(relation), DROPPED_COLUMN_INDEX(i));
RelationGetRelid(relation), DROPPED_COLUMN_INDEX(i));
if (!HeapTupleIsValid(atttup))
#endif /* _DROP_COLUMN_HACK__ */
elog(ERROR, "cannot find attribute %d of relation %s", i,
RelationGetRelationName(relation));
#endif /* _DROP_COLUMN_HACK__ */
elog(ERROR, "cannot find attribute %d of relation %s", i,
RelationGetRelationName(relation));
#ifdef _DROP_COLUMN_HACK__
columnDropped = true;
}
#endif /* _DROP_COLUMN_HACK__ */
#endif /* _DROP_COLUMN_HACK__ */
attp = (Form_pg_attribute) GETSTRUCT(atttup);
relation->rd_att->attrs[i - 1] =
@ -610,7 +613,7 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo,
#ifdef _DROP_COLUMN_HACK__
if (columnDropped)
continue;
#endif /* _DROP_COLUMN_HACK__ */
#endif /* _DROP_COLUMN_HACK__ */
/* Update if this attribute have a constraint */
if (attp->attnotnull)
constr->has_not_null = true;
@ -758,7 +761,7 @@ RelationBuildRuleLock(Relation relation)
static void
FreeRuleLock(RuleLock *rlock)
{
int i;
int i;
if (rlock == NULL)
return;
@ -787,8 +790,8 @@ FreeRuleLock(RuleLock *rlock)
static bool
equalRuleLocks(RuleLock *rlock1, RuleLock *rlock2)
{
int i,
j;
int i,
j;
if (rlock1 != NULL)
{
@ -821,9 +824,9 @@ equalRuleLocks(RuleLock *rlock1, RuleLock *rlock2)
return false;
if (rule1->isInstead != rule2->isInstead)
return false;
if (! equal(rule1->qual, rule2->qual))
if (!equal(rule1->qual, rule2->qual))
return false;
if (! equal(rule1->actions, rule2->actions))
if (!equal(rule1->actions, rule2->actions))
return false;
}
}
@ -852,7 +855,7 @@ equalRuleLocks(RuleLock *rlock1, RuleLock *rlock2)
* Form_pg_am rd_am; AM tuple
* Form_pg_class rd_rel; RELATION tuple
* Oid rd_id; relation's object id
* LockInfoData rd_lockInfo; lock manager's info
* LockInfoData rd_lockInfo; lock manager's info
* TupleDesc rd_att; tuple descriptor
*
* Note: rd_ismem (rel is in-memory only) is currently unused
@ -1309,7 +1312,7 @@ RelationNameGetRelation(const char *relationName)
* ----------------
*/
buildinfo.infotype = INFO_RELNAME;
buildinfo.i.info_name = (char *)relationName;
buildinfo.i.info_name = (char *) relationName;
rd = RelationBuildDesc(buildinfo, NULL);
return rd;
@ -1352,11 +1355,11 @@ RelationClearRelation(Relation relation, bool rebuildIt)
MemoryContext oldcxt;
/*
* Make sure smgr and lower levels close the relation's files,
* if they weren't closed already. We do this unconditionally;
* if the relation is not deleted, the next smgr access should
* reopen the files automatically. This ensures that the low-level
* file access state is updated after, say, a vacuum truncation.
* Make sure smgr and lower levels close the relation's files, if they
* weren't closed already. We do this unconditionally; if the
* relation is not deleted, the next smgr access should reopen the
* files automatically. This ensures that the low-level file access
* state is updated after, say, a vacuum truncation.
*
* NOTE: this call is a no-op if the relation's smgr file is already
* closed or unlinked.
@ -1364,15 +1367,16 @@ RelationClearRelation(Relation relation, bool rebuildIt)
smgrclose(DEFAULT_SMGR, relation);
/*
* Never, never ever blow away a nailed-in system relation,
* because we'd be unable to recover.
* Never, never ever blow away a nailed-in system relation, because
* we'd be unable to recover.
*/
if (relation->rd_isnailed)
return;
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
/* Remove relation from hash tables
/*
* Remove relation from hash tables
*
* Note: we might be reinserting it momentarily, but we must not have it
* visible in the hash tables until it's valid again, so don't try to
@ -1384,12 +1388,12 @@ RelationClearRelation(Relation relation, bool rebuildIt)
SystemCacheRelationFlushed(RelationGetRelid(relation));
/*
* Free all the subsidiary data structures of the relcache entry.
* We cannot free rd_att if we are trying to rebuild the entry,
* however, because pointers to it may be cached in various places.
* The trigger manager might also have pointers into the trigdesc,
* and the rule manager might have pointers into the rewrite rules.
* So to begin with, we can only get rid of these fields:
* Free all the subsidiary data structures of the relcache entry. We
* cannot free rd_att if we are trying to rebuild the entry, however,
* because pointers to it may be cached in various places. The trigger
* manager might also have pointers into the trigdesc, and the rule
* manager might have pointers into the rewrite rules. So to begin
* with, we can only get rid of these fields:
*/
if (relation->rd_am)
pfree(relation->rd_am);
@ -1401,12 +1405,12 @@ RelationClearRelation(Relation relation, bool rebuildIt)
pfree(relation->rd_support);
/*
* If we're really done with the relcache entry, blow it away.
* But if someone is still using it, reconstruct the whole deal
* without moving the physical RelationData record (so that the
* someone's pointer is still valid).
* If we're really done with the relcache entry, blow it away. But if
* someone is still using it, reconstruct the whole deal without
* moving the physical RelationData record (so that the someone's
* pointer is still valid).
*/
if (! rebuildIt)
if (!rebuildIt)
{
/* ok to zap remaining substructure */
FreeTupleDesc(relation->rd_att);
@ -1416,20 +1420,21 @@ RelationClearRelation(Relation relation, bool rebuildIt)
}
else
{
/*
* When rebuilding an open relcache entry, must preserve ref count
* and myxactonly flag. Also attempt to preserve the tupledesc,
* rewrite rules, and trigger substructures in place.
* Furthermore we save/restore rd_nblocks (in case it is a local
* relation) *and* call RelationGetNumberOfBlocks (in case it isn't).
* rewrite rules, and trigger substructures in place. Furthermore
* we save/restore rd_nblocks (in case it is a local relation)
* *and* call RelationGetNumberOfBlocks (in case it isn't).
*/
uint16 old_refcnt = relation->rd_refcnt;
bool old_myxactonly = relation->rd_myxactonly;
TupleDesc old_att = relation->rd_att;
RuleLock *old_rules = relation->rd_rules;
TriggerDesc *old_trigdesc = relation->trigdesc;
int old_nblocks = relation->rd_nblocks;
bool relDescChanged = false;
uint16 old_refcnt = relation->rd_refcnt;
bool old_myxactonly = relation->rd_myxactonly;
TupleDesc old_att = relation->rd_att;
RuleLock *old_rules = relation->rd_rules;
TriggerDesc *old_trigdesc = relation->trigdesc;
int old_nblocks = relation->rd_nblocks;
bool relDescChanged = false;
RelationBuildDescInfo buildinfo;
buildinfo.infotype = INFO_RELID;
@ -1478,12 +1483,14 @@ RelationClearRelation(Relation relation, bool rebuildIt)
relDescChanged = true;
}
relation->rd_nblocks = old_nblocks;
/* this is kind of expensive, but I think we must do it in case
/*
* this is kind of expensive, but I think we must do it in case
* relation has been truncated...
*/
relation->rd_nblocks = RelationGetNumberOfBlocks(relation);
if (relDescChanged && ! RelationHasReferenceCountZero(relation))
if (relDescChanged && !RelationHasReferenceCountZero(relation))
elog(ERROR, "RelationClearRelation: relation %u modified while in use",
buildinfo.i.info_id);
}
@ -1514,6 +1521,7 @@ RelationFlushRelation(Relation *relationPtr,
{
if (skipLocalRelations)
return; /* don't touch local rels if so commanded */
/*
* Local rels should always be rebuilt, not flushed; the relcache
* entry must live until RelationPurgeLocalRelation().
@ -1522,10 +1530,11 @@ RelationFlushRelation(Relation *relationPtr,
}
else
{
/*
* Nonlocal rels can be dropped from the relcache if not open.
*/
rebuildIt = ! RelationHasReferenceCountZero(relation);
rebuildIt = !RelationHasReferenceCountZero(relation);
}
RelationClearRelation(relation, rebuildIt);
@ -1633,6 +1642,7 @@ RelationFlushIndexes(Relation *r,
void
RelationIdInvalidateRelationCacheByAccessMethodId(Oid accessMethodId)
{
/*
* 25 aug 1992: mao commented out the ht walk below. it should be
* doing the right thing, in theory, but flushing reldescs for index
@ -1641,13 +1651,14 @@ RelationIdInvalidateRelationCacheByAccessMethodId(Oid accessMethodId)
* so i'm turning it off for now. after the release is cut, i'll fix
* this up.
*
* 20 nov 1999: this code has still never done anything, so I'm
* cutting the routine out of the system entirely. tgl
* 20 nov 1999: this code has still never done anything, so I'm cutting
* the routine out of the system entirely. tgl
*/
HashTableWalk(RelationNameCache, (HashtFunc) RelationFlushIndexes,
accessMethodId);
}
#endif
/*
@ -1756,7 +1767,7 @@ RelationPurgeLocalRelation(bool xactCommitted)
Assert(reln != NULL && reln->rd_myxactonly);
reln->rd_myxactonly = false; /* mark it not on list anymore */
reln->rd_myxactonly = false; /* mark it not on list anymore */
newlyCreatedRelns = lnext(newlyCreatedRelns);
pfree(l);
@ -1862,8 +1873,8 @@ AttrDefaultFetch(Relation relation)
HeapTupleData tuple;
HeapTuple htup;
Form_pg_attrdef adform;
IndexScanDesc sd = (IndexScanDesc) NULL;
HeapScanDesc adscan = (HeapScanDesc) NULL;
IndexScanDesc sd = (IndexScanDesc) NULL;
HeapScanDesc adscan = (HeapScanDesc) NULL;
RetrieveIndexResult indexRes;
struct varlena *val;
bool isnull;
@ -1885,7 +1896,7 @@ AttrDefaultFetch(Relation relation)
sd = index_beginscan(irel, false, 1, &skey);
}
else
adscan = heap_beginscan(adrel, false, SnapshotNow, 1, &skey);
adscan = heap_beginscan(adrel, false, SnapshotNow, 1, &skey);
tuple.t_datamcxt = NULL;
tuple.t_data = NULL;
@ -1920,7 +1931,7 @@ AttrDefaultFetch(Relation relation)
continue;
if (attrdef[i].adbin != NULL)
elog(NOTICE, "AttrDefaultFetch: second record found for attr %s in rel %s",
NameStr(relation->rd_att->attrs[adform->adnum - 1]->attname),
NameStr(relation->rd_att->attrs[adform->adnum - 1]->attname),
RelationGetRelationName(relation));
val = (struct varlena *) fastgetattr(htup,
@ -1928,7 +1939,7 @@ AttrDefaultFetch(Relation relation)
adrel->rd_att, &isnull);
if (isnull)
elog(NOTICE, "AttrDefaultFetch: adbin IS NULL for attr %s in rel %s",
NameStr(relation->rd_att->attrs[adform->adnum - 1]->attname),
NameStr(relation->rd_att->attrs[adform->adnum - 1]->attname),
RelationGetRelationName(relation));
attrdef[i].adbin = textout(val);
break;
@ -1962,12 +1973,12 @@ RelCheckFetch(Relation relation)
ConstrCheck *check = relation->rd_att->constr->check;
int ncheck = relation->rd_att->constr->num_check;
Relation rcrel;
Relation irel = (Relation)NULL;
Relation irel = (Relation) NULL;
ScanKeyData skey;
HeapTupleData tuple;
HeapTuple htup;
IndexScanDesc sd = (IndexScanDesc)NULL;
HeapScanDesc rcscan = (HeapScanDesc)NULL;
IndexScanDesc sd = (IndexScanDesc) NULL;
HeapScanDesc rcscan = (HeapScanDesc) NULL;
RetrieveIndexResult indexRes;
Name rcname;
struct varlena *val;
@ -2271,9 +2282,9 @@ write_irels(void)
char finalfilename[MAXPGPATH];
/*
* We must write a temporary file and rename it into place. Otherwise,
* another backend starting at about the same time might crash trying to
* read the partially-complete file.
* We must write a temporary file and rename it into place. Otherwise,
* another backend starting at about the same time might crash trying
* to read the partially-complete file.
*/
snprintf(tempfilename, sizeof(tempfilename), "%s%c%s.%d",
DatabasePath, SEP_CHAR, RELCACHE_INIT_FILENAME, MyProcPid);
@ -2292,19 +2303,18 @@ write_irels(void)
/*
* Build relation descriptors for the critical system indexes without
* resort to the descriptor cache. In order to do this, we set
* ProcessingMode to Bootstrap. The effect of this is to disable indexed
* relation searches -- a necessary step, since we're trying to
* instantiate the index relation descriptors here. Once we have the
* descriptors, nail them into cache so we never lose them.
* resort to the descriptor cache. In order to do this, we set
* ProcessingMode to Bootstrap. The effect of this is to disable
* indexed relation searches -- a necessary step, since we're trying
* to instantiate the index relation descriptors here. Once we have
* the descriptors, nail them into cache so we never lose them.
*/
/* Removed the following ProcessingMode change -- inoue
* At this point
* 1) Catalog Cache isn't initialized
* 2) Relation Cache for the following critical indexes aren't built
oldmode = GetProcessingMode();
SetProcessingMode(BootstrapProcessing);
/*
* Removed the following ProcessingMode change -- inoue At this point
* 1) Catalog Cache isn't initialized 2) Relation Cache for the
* following critical indexes aren't built oldmode =
* GetProcessingMode(); SetProcessingMode(BootstrapProcessing);
*/
bi.infotype = INFO_RELNAME;
@ -2321,8 +2331,10 @@ write_irels(void)
irel[2]->rd_isnailed = true;
criticalRelcacheBuild = true;
/* Removed the following ProcessingMode -- inoue
SetProcessingMode(oldmode);
/*
* Removed the following ProcessingMode -- inoue
* SetProcessingMode(oldmode);
*/
/*
@ -2411,9 +2423,9 @@ write_irels(void)
FileClose(fd);
/*
* And rename the temp file to its final name, deleting any previously-
* existing init file.
*/
rename(tempfilename, finalfilename);
/*
* And rename the temp file to its final name, deleting any
* previously- existing init file.
*/
rename(tempfilename, finalfilename);
}

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.49 2000/02/18 09:28:56 inoue Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.50 2000/04/12 17:15:54 momjian Exp $
*
* NOTES
* These routines allow the parser/planner/executor to perform
@ -57,28 +57,28 @@ typedef HeapTuple (*ScanFunc) ();
the list sorted alphabetically and adjust the cache numbers
accordingly.
Add your entry to the cacheinfo[] array below. All cache lists are
Add your entry to the cacheinfo[] array below. All cache lists are
alphabetical, so add it in the proper place. Specify the relation
name, number of arguments, argument names, size of tuple, index lookup
name, number of arguments, argument names, size of tuple, index lookup
function, and index name.
In include/catalog/indexing.h, add a define for the number of indexes
in the relation, add a define for the index name, add an extern
array to hold the index names, define the index lookup function
prototype, and use DECLARE_UNIQUE_INDEX to define the index. Cache
lookups return only one row, so the index should be unique.
In include/catalog/indexing.h, add a define for the number of indexes
in the relation, add a define for the index name, add an extern
array to hold the index names, define the index lookup function
prototype, and use DECLARE_UNIQUE_INDEX to define the index. Cache
lookups return only one row, so the index should be unique.
In backend/catalog/indexing.c, initialize the relation array with
the index names for the relation, fixed size of relation (or marking
first non-fixed length field), and create the index lookup function.
Pick one that takes similar arguments and use that one, but keep the
function names in the same order as the cache list for clarity.
In backend/catalog/indexing.c, initialize the relation array with
the index names for the relation, fixed size of relation (or marking
first non-fixed length field), and create the index lookup function.
Pick one that takes similar arguments and use that one, but keep the
function names in the same order as the cache list for clarity.
Finally, any place your relation gets heap_insert() or
Finally, any place your relation gets heap_insert() or
heap_update calls, include code to do a CatalogIndexInsert() to update
the system indexes. The heap_* calls do not update indexes.
bjm 1999/11/22
bjm 1999/11/22
---------------------------------------------------------------------------
*/
@ -394,10 +394,12 @@ static struct cachedesc cacheinfo[] = {
TypeOidIndexScan}
};
static struct catcache *SysCache[lengthof(cacheinfo)];
static struct catcache *SysCache[
lengthof(cacheinfo)];
static int32 SysCacheSize = lengthof(cacheinfo);
static bool CacheInitialized = false;
extern bool IsCacheInitialized(void)
static bool CacheInitialized = false;
extern bool
IsCacheInitialized(void)
{
return CacheInitialized;
}
@ -520,7 +522,7 @@ SearchSysCacheTuple(int cacheId,/* cache selection code */
/* temp table name remapping */
if (cacheId == RELNAME)
{
char *nontemp_relname;
char *nontemp_relname;
if ((nontemp_relname =
get_temp_rel_by_username(DatumGetPointer(key1))) != NULL)
@ -549,7 +551,7 @@ SearchSysCacheTuple(int cacheId,/* cache selection code */
* SearchSysCacheTupleCopy(), extract a specific attribute.
*
* This is equivalent to using heap_getattr() on a tuple fetched
* from a non-cached relation. Usually, this is only used for attributes
* from a non-cached relation. Usually, this is only used for attributes
* that could be NULL or variable length; the fixed-size attributes in
* a system table are accessed just by mapping the tuple onto the C struct
* declarations from include/catalog/.
@ -563,17 +565,18 @@ SysCacheGetAttr(int cacheId, HeapTuple tup,
AttrNumber attributeNumber,
bool *isnull)
{
/*
* We just need to get the TupleDesc out of the cache entry,
* and then we can apply heap_getattr(). We expect that the cache
* control data is currently valid --- if the caller just fetched
* the tuple, then it should be.
* We just need to get the TupleDesc out of the cache entry, and then
* we can apply heap_getattr(). We expect that the cache control data
* is currently valid --- if the caller just fetched the tuple, then
* it should be.
*/
if (cacheId < 0 || cacheId >= SysCacheSize)
elog(ERROR, "SysCacheGetAttr: Bad cache id %d", cacheId);
if (! PointerIsValid(SysCache[cacheId]) ||
if (!PointerIsValid(SysCache[cacheId]) ||
SysCache[cacheId]->relationId == InvalidOid ||
! PointerIsValid(SysCache[cacheId]->cc_tupdesc))
!PointerIsValid(SysCache[cacheId]->cc_tupdesc))
elog(ERROR, "SysCacheGetAttr: missing cache data for id %d", cacheId);
return heap_getattr(tup, attributeNumber,

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.20 2000/01/26 05:57:18 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.21 2000/04/12 17:15:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -64,7 +64,7 @@ create_temp_relation(const char *relname, HeapTuple pg_class_tuple)
/* save user-supplied name */
strcpy(temp_rel->user_relname, relname);
StrNCpy(temp_rel->relname, NameStr(((Form_pg_class)
GETSTRUCT(pg_class_tuple))->relname), NAMEDATALEN);
GETSTRUCT(pg_class_tuple))->relname), NAMEDATALEN);
temp_rel->relid = pg_class_tuple->t_data->t_oid;
temp_rel->relkind = ((Form_pg_class) GETSTRUCT(pg_class_tuple))->relkind;
temp_rel->xid = GetCurrentTransactionId();
@ -95,7 +95,7 @@ remove_all_temp_relations(void)
if (temp_rel->relkind != RELKIND_INDEX)
{
char relname[NAMEDATALEN];
char relname[NAMEDATALEN];
/* safe from deallocation */
strcpy(relname, temp_rel->user_relname);
@ -118,7 +118,7 @@ remove_temp_relation(Oid relid)
MemoryContext oldcxt;
List *l,
*prev;
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
prev = NIL;