mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Allow indexes on system catalogs for use in cache code.
Thanks to Hiroshi
This commit is contained in:
69
src/backend/utils/cache/catcache.c
vendored
69
src/backend/utils/cache/catcache.c
vendored
@ -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);
|
||||
@ -805,6 +808,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
|
||||
*
|
||||
@ -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
|
||||
* ----------------
|
||||
|
25
src/backend/utils/cache/syscache.c
vendored
25
src/backend/utils/cache/syscache.c
vendored
@ -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,
|
||||
{
|
||||
|
Reference in New Issue
Block a user