diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/catalog/index.c | 34 | ||||
-rw-r--r-- | src/backend/catalog/indexing.c | 113 | ||||
-rw-r--r-- | src/backend/utils/cache/catcache.c | 69 | ||||
-rw-r--r-- | src/backend/utils/cache/syscache.c | 25 |
4 files changed, 203 insertions, 38 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9e7850f8f63..a8c2adf7cbd 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.92 1999/10/26 03:12:33 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.93 1999/11/01 02:29:24 momjian Exp $ * * * INTERFACE ROUTINES @@ -54,26 +54,23 @@ /* non-export function prototypes */ static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName, - bool istemp); + bool istemp); static TupleDesc BuildFuncTupleDesc(FuncIndexInfo *funcInfo); static TupleDesc ConstructTupleDescriptor(Oid heapoid, Relation heapRelation, - List *attributeList, - int numatts, AttrNumber *attNums); + List *attributeList, int numatts, AttrNumber *attNums); static void ConstructIndexReldesc(Relation indexRelation, Oid amoid); static Oid UpdateRelationRelation(Relation indexRelation, char *temp_relname); static void InitializeAttributeOids(Relation indexRelation, - int numatts, - Oid indexoid); -static void - AppendAttributeTuples(Relation indexRelation, int numatts); + int numatts, Oid indexoid); +static void AppendAttributeTuples(Relation indexRelation, int numatts); static void UpdateIndexRelation(Oid indexoid, Oid heapoid, - FuncIndexInfo *funcInfo, int natts, - AttrNumber *attNums, Oid *classOids, Node *predicate, - List *attributeList, bool islossy, bool unique, bool primary); + FuncIndexInfo *funcInfo, int natts, + AttrNumber *attNums, Oid *classOids, Node *predicate, + List *attributeList, bool islossy, bool unique, bool primary); static void DefaultBuild(Relation heapRelation, Relation indexRelation, - int numberOfAttributes, AttrNumber *attributeNumber, - IndexStrategy indexStrategy, uint16 parameterCount, + int numberOfAttributes, AttrNumber *attributeNumber, + IndexStrategy indexStrategy, uint16 parameterCount, Datum *parameter, FuncIndexInfoPtr funcInfo, PredInfo *predInfo); /* ---------------------------------------------------------------- @@ -661,6 +658,7 @@ UpdateIndexRelation(Oid indexoid, Relation pg_index; HeapTuple tuple; int i; + Relation idescs[Num_pg_index_indices]; /* ---------------- * allocate an Form_pg_index big enough to hold the @@ -753,6 +751,16 @@ UpdateIndexRelation(Oid indexoid, heap_insert(pg_index, tuple); /* ---------------- + * insert the index tuple into the pg_index + * ---------------- + */ + if (!IsBootstrapProcessingMode()) + { + CatalogOpenIndices(Num_pg_index_indices, Name_pg_index_indices, idescs); + CatalogIndexInsert(idescs, Num_pg_index_indices, pg_index, tuple); + CatalogCloseIndices(Num_pg_index_indices, idescs); + } + /* ---------------- * close the relation and free the tuple * ---------------- */ diff --git a/src/backend/catalog/indexing.c b/src/backend/catalog/indexing.c index 2caffcbcf5c..c8d1bf05535 100644 --- a/src/backend/catalog/indexing.c +++ b/src/backend/catalog/indexing.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.48 1999/10/15 01:49:39 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.49 1999/11/01 02:29:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -38,15 +38,17 @@ * pg_trigger */ +char *Name_pg_amop_indices[Num_pg_amop_indices] = {AccessMethodOpidIndex, + AccessMethodStrategyIndex}; char *Name_pg_attr_indices[Num_pg_attr_indices] = {AttributeNameIndex, - AttributeNumIndex, -AttributeRelidIndex}; + AttributeNumIndex, AttributeRelidIndex}; +char *Name_pg_index_indices[Num_pg_index_indices] = {IndexRelidIndex}; char *Name_pg_proc_indices[Num_pg_proc_indices] = {ProcedureNameIndex, - ProcedureOidIndex}; + ProcedureOidIndex}; char *Name_pg_type_indices[Num_pg_type_indices] = {TypeNameIndex, -TypeOidIndex}; + TypeOidIndex}; char *Name_pg_class_indices[Num_pg_class_indices] = {ClassNameIndex, -ClassOidIndex}; + ClassOidIndex}; char *Name_pg_attrdef_indices[Num_pg_attrdef_indices] = {AttrDefaultIndex}; char *Name_pg_relcheck_indices[Num_pg_relcheck_indices] = {RelCheckIndex}; @@ -255,6 +257,11 @@ CatalogIndexFetchTuple(Relation heapRelation, } +/*--------------------------------------------------------------------- + * Class-specific index lookups + *--------------------------------------------------------------------- + */ + /* * The remainder of the file is for individual index scan routines. Each * index should be scanned according to how it was defined during bootstrap @@ -262,6 +269,78 @@ CatalogIndexFetchTuple(Relation heapRelation, * requires. Each routine returns the heap tuple that qualifies. */ HeapTuple +AccessMethodOpidIndexScan(Relation heapRelation, + Oid claid, + Oid opopr, + Oid opid) +{ + Relation idesc; + ScanKeyData skey[3]; + HeapTuple tuple; + + ScanKeyEntryInitialize(&skey[0], + (bits16) 0x0, + (AttrNumber) 1, + (RegProcedure) F_OIDEQ, + ObjectIdGetDatum(claid)); + + ScanKeyEntryInitialize(&skey[1], + (bits16) 0x0, + (AttrNumber) 2, + (RegProcedure) F_OIDEQ, + ObjectIdGetDatum(opopr)); + + ScanKeyEntryInitialize(&skey[2], + (bits16) 0x0, + (AttrNumber) 3, + (RegProcedure) F_OIDEQ, + ObjectIdGetDatum(opid)); + + idesc = index_openr(AccessMethodOpidIndex); + tuple = CatalogIndexFetchTuple(heapRelation, idesc, skey, 3); + + index_close(idesc); + + return tuple; +} + +HeapTuple +AccessMethodStrategyIndexScan(Relation heapRelation, + Oid opid, + Oid claid, + int2 opstrategy) +{ + Relation idesc; + ScanKeyData skey[3]; + HeapTuple tuple; + + ScanKeyEntryInitialize(&skey[0], + (bits16) 0x0, + (AttrNumber) 1, + (RegProcedure) F_OIDEQ, + ObjectIdGetDatum(opid)); + + ScanKeyEntryInitialize(&skey[1], + (bits16) 0x0, + (AttrNumber) 2, + (RegProcedure) F_OIDEQ, + ObjectIdGetDatum(claid)); + + ScanKeyEntryInitialize(&skey[2], + (bits16) 0x0, + (AttrNumber) 3, + (RegProcedure) F_INT2EQ, + Int16GetDatum(opstrategy)); + + idesc = index_openr(AccessMethodStrategyIndex); + tuple = CatalogIndexFetchTuple(heapRelation, idesc, skey, 3); + + index_close(idesc); + + return tuple; +} + +HeapTuple AttributeNameIndexScan(Relation heapRelation, Oid relid, char *attname) @@ -320,6 +399,28 @@ AttributeNumIndexScan(Relation heapRelation, return tuple; } +HeapTuple +IndexRelidIndexScan(Relation heapRelation, Oid relid) +{ + Relation idesc; + ScanKeyData skey[1]; + HeapTuple tuple; + + ScanKeyEntryInitialize(&skey[0], + (bits16) 0x0, + (AttrNumber) 1, + (RegProcedure) F_OIDEQ, + ObjectIdGetDatum(relid)); + + idesc = index_openr(IndexRelidIndex); + tuple = CatalogIndexFetchTuple(heapRelation, idesc, skey, 1); + + index_close(idesc); + + return tuple; +} + + HeapTuple ProcedureOidIndexScan(Relation heapRelation, Oid procId) 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, { |