Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd16b706

Browse files
committed
Allow indexes on system catalogs for use in cache code.
Thanks to Hiroshi
1 parent1973e90 commitd16b706

File tree

6 files changed

+237
-53
lines changed

6 files changed

+237
-53
lines changed

‎src/backend/catalog/index.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.92 1999/10/26 03:12:33 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.93 1999/11/01 02:29:24 momjian Exp $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -54,26 +54,23 @@
5454

5555
/* non-export function prototypes */
5656
staticOidGetHeapRelationOid(char*heapRelationName,char*indexRelationName,
57-
boolistemp);
57+
boolistemp);
5858
staticTupleDescBuildFuncTupleDesc(FuncIndexInfo*funcInfo);
5959
staticTupleDescConstructTupleDescriptor(Oidheapoid,RelationheapRelation,
60-
List*attributeList,
61-
intnumatts,AttrNumber*attNums);
60+
List*attributeList,intnumatts,AttrNumber*attNums);
6261

6362
staticvoidConstructIndexReldesc(RelationindexRelation,Oidamoid);
6463
staticOidUpdateRelationRelation(RelationindexRelation,char*temp_relname);
6564
staticvoidInitializeAttributeOids(RelationindexRelation,
66-
intnumatts,
67-
Oidindexoid);
68-
staticvoid
69-
AppendAttributeTuples(RelationindexRelation,intnumatts);
65+
intnumatts,Oidindexoid);
66+
staticvoidAppendAttributeTuples(RelationindexRelation,intnumatts);
7067
staticvoidUpdateIndexRelation(Oidindexoid,Oidheapoid,
71-
FuncIndexInfo*funcInfo,intnatts,
72-
AttrNumber*attNums,Oid*classOids,Node*predicate,
73-
List*attributeList,boolislossy,boolunique,boolprimary);
68+
FuncIndexInfo*funcInfo,intnatts,
69+
AttrNumber*attNums,Oid*classOids,Node*predicate,
70+
List*attributeList,boolislossy,boolunique,boolprimary);
7471
staticvoidDefaultBuild(RelationheapRelation,RelationindexRelation,
75-
intnumberOfAttributes,AttrNumber*attributeNumber,
76-
IndexStrategyindexStrategy,uint16parameterCount,
72+
intnumberOfAttributes,AttrNumber*attributeNumber,
73+
IndexStrategyindexStrategy,uint16parameterCount,
7774
Datum*parameter,FuncIndexInfoPtrfuncInfo,PredInfo*predInfo);
7875

7976
/* ----------------------------------------------------------------
@@ -661,6 +658,7 @@ UpdateIndexRelation(Oid indexoid,
661658
Relationpg_index;
662659
HeapTupletuple;
663660
inti;
661+
Relationidescs[Num_pg_index_indices];
664662

665663
/* ----------------
666664
*allocate an Form_pg_index big enough to hold the
@@ -752,6 +750,16 @@ UpdateIndexRelation(Oid indexoid,
752750
*/
753751
heap_insert(pg_index,tuple);
754752

753+
/* ----------------
754+
*insert the index tuple into the pg_index
755+
* ----------------
756+
*/
757+
if (!IsBootstrapProcessingMode())
758+
{
759+
CatalogOpenIndices(Num_pg_index_indices,Name_pg_index_indices,idescs);
760+
CatalogIndexInsert(idescs,Num_pg_index_indices,pg_index,tuple);
761+
CatalogCloseIndices(Num_pg_index_indices,idescs);
762+
}
755763
/* ----------------
756764
*close the relation and free the tuple
757765
* ----------------

‎src/backend/catalog/indexing.c

Lines changed: 107 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.48 1999/10/15 01:49:39 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.49 1999/11/01 02:29:25 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -38,15 +38,17 @@
3838
*pg_trigger
3939
*/
4040

41+
char*Name_pg_amop_indices[Num_pg_amop_indices]= {AccessMethodOpidIndex,
42+
AccessMethodStrategyIndex};
4143
char*Name_pg_attr_indices[Num_pg_attr_indices]= {AttributeNameIndex,
42-
AttributeNumIndex,
43-
AttributeRelidIndex};
44+
AttributeNumIndex,AttributeRelidIndex};
45+
char*Name_pg_index_indices[Num_pg_index_indices]= {IndexRelidIndex};
4446
char*Name_pg_proc_indices[Num_pg_proc_indices]= {ProcedureNameIndex,
45-
ProcedureOidIndex};
47+
ProcedureOidIndex};
4648
char*Name_pg_type_indices[Num_pg_type_indices]= {TypeNameIndex,
47-
TypeOidIndex};
49+
TypeOidIndex};
4850
char*Name_pg_class_indices[Num_pg_class_indices]= {ClassNameIndex,
49-
ClassOidIndex};
51+
ClassOidIndex};
5052
char*Name_pg_attrdef_indices[Num_pg_attrdef_indices]= {AttrDefaultIndex};
5153

5254
char*Name_pg_relcheck_indices[Num_pg_relcheck_indices]= {RelCheckIndex};
@@ -255,12 +257,89 @@ CatalogIndexFetchTuple(Relation heapRelation,
255257
}
256258

257259

260+
/*---------------------------------------------------------------------
261+
* Class-specific index lookups
262+
*---------------------------------------------------------------------
263+
*/
264+
258265
/*
259266
* The remainder of the file is for individual index scan routines. Each
260267
* index should be scanned according to how it was defined during bootstrap
261268
* (that is, functional or normal) and what arguments the cache lookup
262269
* requires. Each routine returns the heap tuple that qualifies.
263270
*/
271+
HeapTuple
272+
AccessMethodOpidIndexScan(RelationheapRelation,
273+
Oidclaid,
274+
Oidopopr,
275+
Oidopid)
276+
{
277+
Relationidesc;
278+
ScanKeyDataskey[3];
279+
HeapTupletuple;
280+
281+
ScanKeyEntryInitialize(&skey[0],
282+
(bits16)0x0,
283+
(AttrNumber)1,
284+
(RegProcedure)F_OIDEQ,
285+
ObjectIdGetDatum(claid));
286+
287+
ScanKeyEntryInitialize(&skey[1],
288+
(bits16)0x0,
289+
(AttrNumber)2,
290+
(RegProcedure)F_OIDEQ,
291+
ObjectIdGetDatum(opopr));
292+
293+
ScanKeyEntryInitialize(&skey[2],
294+
(bits16)0x0,
295+
(AttrNumber)3,
296+
(RegProcedure)F_OIDEQ,
297+
ObjectIdGetDatum(opid));
298+
299+
idesc=index_openr(AccessMethodOpidIndex);
300+
tuple=CatalogIndexFetchTuple(heapRelation,idesc,skey,3);
301+
302+
index_close(idesc);
303+
304+
returntuple;
305+
}
306+
307+
HeapTuple
308+
AccessMethodStrategyIndexScan(RelationheapRelation,
309+
Oidopid,
310+
Oidclaid,
311+
int2opstrategy)
312+
{
313+
Relationidesc;
314+
ScanKeyDataskey[3];
315+
HeapTupletuple;
316+
317+
ScanKeyEntryInitialize(&skey[0],
318+
(bits16)0x0,
319+
(AttrNumber)1,
320+
(RegProcedure)F_OIDEQ,
321+
ObjectIdGetDatum(opid));
322+
323+
ScanKeyEntryInitialize(&skey[1],
324+
(bits16)0x0,
325+
(AttrNumber)2,
326+
(RegProcedure)F_OIDEQ,
327+
ObjectIdGetDatum(claid));
328+
329+
ScanKeyEntryInitialize(&skey[2],
330+
(bits16)0x0,
331+
(AttrNumber)3,
332+
(RegProcedure)F_INT2EQ,
333+
Int16GetDatum(opstrategy));
334+
335+
idesc=index_openr(AccessMethodStrategyIndex);
336+
tuple=CatalogIndexFetchTuple(heapRelation,idesc,skey,3);
337+
338+
index_close(idesc);
339+
340+
returntuple;
341+
}
342+
264343
HeapTuple
265344
AttributeNameIndexScan(RelationheapRelation,
266345
Oidrelid,
@@ -320,6 +399,28 @@ AttributeNumIndexScan(Relation heapRelation,
320399
returntuple;
321400
}
322401

402+
HeapTuple
403+
IndexRelidIndexScan(RelationheapRelation,Oidrelid)
404+
{
405+
Relationidesc;
406+
ScanKeyDataskey[1];
407+
HeapTupletuple;
408+
409+
ScanKeyEntryInitialize(&skey[0],
410+
(bits16)0x0,
411+
(AttrNumber)1,
412+
(RegProcedure)F_OIDEQ,
413+
ObjectIdGetDatum(relid));
414+
415+
idesc=index_openr(IndexRelidIndex);
416+
tuple=CatalogIndexFetchTuple(heapRelation,idesc,skey,1);
417+
418+
index_close(idesc);
419+
420+
returntuple;
421+
}
422+
423+
323424

324425
HeapTuple
325426
ProcedureOidIndexScan(RelationheapRelation,OidprocId)

‎src/backend/utils/cache/catcache.c

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.49 1999/09/18 19:07:55 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.50 1999/11/01 02:29:25 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -16,9 +16,12 @@
1616
#include"access/heapam.h"
1717
#include"access/valid.h"
1818
#include"catalog/pg_type.h"
19+
#include"catalog/catname.h"
20+
#include"catalog/indexing.h"
1921
#include"miscadmin.h"
2022
#include"utils/builtins.h"
2123
#include"utils/catcache.h"
24+
#include"utils/syscache.h"
2225

2326
staticvoidCatCacheRemoveCTup(CatCache*cache,Dlelem*e);
2427
staticIndexCatalogCacheComputeHashIndex(structcatcache*cacheInP);
@@ -805,6 +808,62 @@ InitSysCache(char *relname,
805808
}
806809

807810

811+
/* --------------------------------
812+
*SearchSelfReferences
813+
*
814+
*This call searches a self referencing information,
815+
*
816+
*which causes a cycle in system catalog cache
817+
*
818+
*cache should already be initailized
819+
* --------------------------------
820+
*/
821+
staticHeapTuple
822+
SearchSelfReferences(conststructcatcache*cache)
823+
{
824+
HeapTuplentp;
825+
Relationrel;
826+
staticOidindexSelfOid=0;
827+
staticHeapTupleindexSelfTuple=0;
828+
829+
if (cache->id!=INDEXRELID)
830+
return (HeapTuple)0;
831+
832+
if (!indexSelfOid)
833+
{
834+
rel=heap_openr(RelationRelationName,AccessShareLock);
835+
ntp=ClassNameIndexScan(rel,IndexRelidIndex);
836+
if (!HeapTupleIsValid(ntp))
837+
elog(ERROR,"SearchSelfRefernces: %s not found in %s",
838+
IndexRelidIndex,RelationRelationName);
839+
indexSelfOid=ntp->t_data->t_oid;
840+
pfree(ntp);
841+
heap_close(rel,AccessShareLock);
842+
}
843+
if ((Oid)cache->cc_skey[0].sk_argument!=indexSelfOid)
844+
return (HeapTuple)0;
845+
if (!indexSelfTuple)
846+
{
847+
HeapScanDescsd;
848+
MemoryContextoldcxt;
849+
850+
if (!CacheCxt)
851+
CacheCxt=CreateGlobalMemory("Cache");
852+
rel=heap_open(cache->relationId,AccessShareLock);
853+
sd=heap_beginscan(rel, false,SnapshotNow,1,cache->cc_skey);
854+
ntp=heap_getnext(sd,0);
855+
if (!HeapTupleIsValid(ntp))
856+
elog(ERROR,"SearchSelfRefernces: tuple not found");
857+
oldcxt=MemoryContextSwitchTo((MemoryContext)CacheCxt);
858+
indexSelfTuple=heap_copytuple(ntp);
859+
MemoryContextSwitchTo(oldcxt);
860+
heap_endscan(sd);
861+
heap_close(rel,AccessShareLock);
862+
}
863+
864+
returnindexSelfTuple;
865+
}
866+
808867
/* --------------------------------
809868
*SearchSysCache
810869
*
@@ -845,6 +904,14 @@ SearchSysCache(struct catcache * cache,
845904
cache->cc_skey[2].sk_argument=v3;
846905
cache->cc_skey[3].sk_argument=v4;
847906

907+
/*
908+
*resolve self referencing informtion
909+
*/
910+
if (ntp=SearchSelfReferences(cache),ntp)
911+
{
912+
returnheap_copytuple(ntp);
913+
}
914+
848915
/* ----------------
849916
*find the hash bucket in which to look for the tuple
850917
* ----------------

‎src/backend/utils/cache/syscache.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.37 1999/09/30 10:31:43 wieck Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.38 1999/11/01 02:29:25 momjian Exp $
1111
*
1212
* NOTES
1313
* These routines allow the parser/planner/executor to perform
@@ -59,8 +59,8 @@ static struct cachedesc cacheinfo[] = {
5959
0
6060
},
6161
sizeof(FormData_pg_amop),
62-
NULL,
63-
(ScanFunc)NULL},
62+
AccessMethodOpidIndex,
63+
(ScanFunc)AccessMethodOpidIndexScan},
6464
{AccessMethodOperatorRelationName,/* AMOPSTRATEGY */
6565
3,
6666
{
@@ -70,8 +70,8 @@ static struct cachedesc cacheinfo[] = {
7070
0
7171
},
7272
sizeof(FormData_pg_amop),
73-
NULL,
74-
(ScanFunc)NULL},
73+
AccessMethodStrategyIndex,
74+
(ScanFunc)AccessMethodStrategyIndexScan},
7575
{AttributeRelationName,/* ATTNAME */
7676
2,
7777
{
@@ -103,8 +103,8 @@ static struct cachedesc cacheinfo[] = {
103103
0
104104
},
105105
offsetof(FormData_pg_index,indpred),
106-
NULL,
107-
NULL},
106+
IndexRelidIndex,
107+
(ScanFunc)IndexRelidIndexScan},
108108
{LanguageRelationName,/* LANNAME */
109109
1,
110110
{
@@ -226,17 +226,6 @@ static struct cachedesc cacheinfo[] = {
226226
sizeof(FormData_pg_opclass),
227227
NULL,
228228
NULL},
229-
{IndexRelationName,/* INDRELIDKEY *//* never used */
230-
2,
231-
{
232-
Anum_pg_index_indrelid,
233-
Anum_pg_index_indkey,
234-
0,
235-
0
236-
},
237-
offsetof(FormData_pg_index,indpred),
238-
NULL,
239-
(ScanFunc)NULL},
240229
{InheritsRelationName,/* INHRELID */
241230
2,
242231
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp