diff options
Diffstat (limited to 'src/backend/utils/cache')
-rw-r--r-- | src/backend/utils/cache/catcache.c | 69 | ||||
-rw-r--r-- | src/backend/utils/cache/syscache.c | 25 |
2 files changed, 75 insertions, 19 deletions
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index 22d933bb37a..d3c022c2479 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.49 1999/09/18 19:07:55 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.50 1999/11/01 02:29:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -16,9 +16,12 @@ #include "access/heapam.h" #include "access/valid.h" #include "catalog/pg_type.h" +#include "catalog/catname.h" +#include "catalog/indexing.h" #include "miscadmin.h" #include "utils/builtins.h" #include "utils/catcache.h" +#include "utils/syscache.h" static void CatCacheRemoveCTup(CatCache *cache, Dlelem *e); static Index CatalogCacheComputeHashIndex(struct catcache * cacheInP); @@ -806,6 +809,62 @@ InitSysCache(char *relname, /* -------------------------------- + * SearchSelfReferences + * + * This call searches a self referencing information, + * + * which causes a cycle in system catalog cache + * + * cache should already be initailized + * -------------------------------- + */ +static HeapTuple +SearchSelfReferences(const struct catcache * cache) +{ + HeapTuple ntp; + Relation rel; + static Oid indexSelfOid = 0; + static HeapTuple indexSelfTuple = 0; + + if (cache->id != INDEXRELID) + return (HeapTuple)0; + + if (!indexSelfOid) + { + rel = heap_openr(RelationRelationName, AccessShareLock); + ntp = ClassNameIndexScan(rel, IndexRelidIndex); + if (!HeapTupleIsValid(ntp)) + elog(ERROR, "SearchSelfRefernces: %s not found in %s", + IndexRelidIndex, RelationRelationName); + indexSelfOid = ntp->t_data->t_oid; + pfree(ntp); + heap_close(rel, AccessShareLock); + } + if ((Oid)cache->cc_skey[0].sk_argument != indexSelfOid) + return (HeapTuple)0; + if (!indexSelfTuple) + { + HeapScanDesc sd; + MemoryContext oldcxt; + + if (!CacheCxt) + CacheCxt = CreateGlobalMemory("Cache"); + rel = heap_open(cache->relationId, AccessShareLock); + sd = heap_beginscan(rel, false, SnapshotNow, 1, cache->cc_skey); + ntp = heap_getnext(sd, 0); + if (!HeapTupleIsValid(ntp)) + elog(ERROR, "SearchSelfRefernces: tuple not found"); + oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt); + indexSelfTuple = heap_copytuple(ntp); + MemoryContextSwitchTo(oldcxt); + heap_endscan(sd); + heap_close(rel, AccessShareLock); + } + + return indexSelfTuple; +} + +/* -------------------------------- * SearchSysCache * * This call searches a system cache for a tuple, opening the relation @@ -845,6 +904,14 @@ SearchSysCache(struct catcache * cache, cache->cc_skey[2].sk_argument = v3; cache->cc_skey[3].sk_argument = v4; + /* + * resolve self referencing informtion + */ + if (ntp = SearchSelfReferences(cache), ntp) + { + return heap_copytuple(ntp); + } + /* ---------------- * find the hash bucket in which to look for the tuple * ---------------- diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c index 53917f92c56..3cb393b802f 100644 --- a/src/backend/utils/cache/syscache.c +++ b/src/backend/utils/cache/syscache.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.37 1999/09/30 10:31:43 wieck Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.38 1999/11/01 02:29:25 momjian Exp $ * * NOTES * These routines allow the parser/planner/executor to perform @@ -59,8 +59,8 @@ static struct cachedesc cacheinfo[] = { 0 }, sizeof(FormData_pg_amop), - NULL, - (ScanFunc) NULL}, + AccessMethodOpidIndex, + (ScanFunc) AccessMethodOpidIndexScan}, {AccessMethodOperatorRelationName, /* AMOPSTRATEGY */ 3, { @@ -70,8 +70,8 @@ static struct cachedesc cacheinfo[] = { 0 }, sizeof(FormData_pg_amop), - NULL, - (ScanFunc) NULL}, + AccessMethodStrategyIndex, + (ScanFunc) AccessMethodStrategyIndexScan}, {AttributeRelationName, /* ATTNAME */ 2, { @@ -103,8 +103,8 @@ static struct cachedesc cacheinfo[] = { 0 }, offsetof(FormData_pg_index, indpred), - NULL, - NULL}, + IndexRelidIndex, + (ScanFunc) IndexRelidIndexScan}, {LanguageRelationName, /* LANNAME */ 1, { @@ -226,17 +226,6 @@ static struct cachedesc cacheinfo[] = { sizeof(FormData_pg_opclass), NULL, NULL}, - {IndexRelationName, /* INDRELIDKEY *//* never used */ - 2, - { - Anum_pg_index_indrelid, - Anum_pg_index_indkey, - 0, - 0 - }, - offsetof(FormData_pg_index, indpred), - NULL, - (ScanFunc) NULL}, {InheritsRelationName, /* INHRELID */ 2, { |