@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $ Header : / cvsroot / pgsql / src / backend / catalog / indexing . c , v 1.50 1999 / 11 / 01 04 : 00 : 56 momjian Exp $
* $ Header : / cvsroot / pgsql / src / backend / catalog / indexing . c , v 1.51 1999 / 11 / 22 17 : 55 : 57 momjian Exp $
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
@ -26,34 +26,49 @@
# include "utils/syscache.h"
/*
* Names of indices on the following system catalogs :
*
* pg_attribute
* pg_proc
* pg_type
* pg_naming
* pg_class
* pg_attrdef
* pg_relcheck
* pg_trigger
* Names of indices - they match all system caches
*/
char * Name_pg_amop_indices [ Num_pg_amop_indices ] = { AccessMethodOpidIndex ,
AccessMethodStrategyIndex } ;
char * Name_pg_attr_indices [ Num_pg_attr_indices ] = { AttributeNameIndex ,
AttributeNumIndex , AttributeRelidIndex } ;
char * Name_pg_index_indices [ Num_pg_index_indices ] = { IndexRelidIndex } ;
char * Name_pg_proc_indices [ Num_pg_proc_indices ] = { ProcedureNameIndex ,
ProcedureOidIndex } ;
char * Name_pg_type_indices [ Num_pg_type_indices ] = { TypeNameIndex ,
TypeOidIndex } ;
char * Name_pg_class_indices [ Num_pg_class_indices ] = { ClassNameIndex ,
ClassOidIndex } ;
char * Name_pg_attrdef_indices [ Num_pg_attrdef_indices ] = { AttrDefaultIndex } ;
char * Name_pg_relcheck_indices [ Num_pg_relcheck_indices ] = { RelCheckIndex } ;
char * Name_pg_trigger_indices [ Num_pg_trigger_indices ] = { TriggerRelidIndex ,
TriggerConstrNameIndex , TriggerConstrRelidIndex } ;
char * Name_pg_description_indices [ Num_pg_description_indices ] = { DescriptionObjIndex } ;
char * Name_pg_aggregate_indices [ Num_pg_aggregate_indices ] =
{ AggregateNameTypeIndex } ;
char * Name_pg_am_indices [ Num_pg_am_indices ] =
{ AmNameIndex } ;
char * Name_pg_amop_indices [ Num_pg_amop_indices ] =
{ AccessMethodOpidIndex , AccessMethodStrategyIndex } ;
char * Name_pg_attr_indices [ Num_pg_attr_indices ] =
{ AttributeRelidNameIndex , AttributeRelidNumIndex } ;
char * Name_pg_attrdef_indices [ Num_pg_attrdef_indices ] =
{ AttrDefaultIndex } ;
char * Name_pg_class_indices [ Num_pg_class_indices ] =
{ ClassNameIndex , ClassOidIndex } ;
char * Name_pg_group_indices [ Num_pg_group_indices ] =
{ GroupNameIndex , GroupSysidIndex } ;
char * Name_pg_index_indices [ Num_pg_index_indices ] =
{ IndexRelidIndex } ;
char * Name_pg_inherits_indices [ Num_pg_inherits_indices ] =
{ InheritsRelidSeqnoIndex } ;
char * Name_pg_language_indices [ Num_pg_language_indices ] =
{ LanguageOidIndex , LanguageNameIndex } ;
char * Name_pg_listener_indices [ Num_pg_listener_indices ] =
{ ListenerRelnamePidIndex } ;
char * Name_pg_opclass_indices [ Num_pg_opclass_indices ] =
{ OpclassNameIndex , OpclassDeftypeIndex } ;
char * Name_pg_operator_indices [ Num_pg_operator_indices ] =
{ OperatorOidIndex , OperatorNameIndex } ;
char * Name_pg_proc_indices [ Num_pg_proc_indices ] =
{ ProcedureOidIndex , ProcedureNameIndex } ;
char * Name_pg_relcheck_indices [ Num_pg_relcheck_indices ] =
{ RelCheckIndex } ;
char * Name_pg_rewrite_indices [ Num_pg_rewrite_indices ] =
{ RewriteOidIndex , RewriteRulenameIndex } ;
char * Name_pg_shadow_indices [ Num_pg_shadow_indices ] =
{ ShadowNameIndex , ShadowSysidIndex } ;
char * Name_pg_trigger_indices [ Num_pg_trigger_indices ] =
{ TriggerRelidIndex , TriggerConstrNameIndex , TriggerConstrRelidIndex } ;
char * Name_pg_type_indices [ Num_pg_type_indices ] =
{ TypeNameIndex , TypeOidIndex } ;
char * Name_pg_description_indices [ Num_pg_description_indices ] =
{ DescriptionObjIndex } ;
@ -264,6 +279,56 @@ CatalogIndexFetchTuple(Relation heapRelation,
* ( that is , functional or normal ) and what arguments the cache lookup
* requires . Each routine returns the heap tuple that qualifies .
*/
HeapTuple
AggregateNameTypeIndexScan ( Relation heapRelation , char * aggName , Oid aggType )
{
Relation idesc ;
ScanKeyData skey [ 2 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_NAMEEQ ,
PointerGetDatum ( aggName ) ) ;
ScanKeyEntryInitialize ( & skey [ 1 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 2 ,
( RegProcedure ) F_OIDEQ ,
ObjectIdGetDatum ( aggType ) ) ;
idesc = index_openr ( AggregateNameTypeIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 2 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
AmNameIndexScan ( Relation heapRelation , char * amName )
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_NAMEEQ ,
PointerGetDatum ( amName ) ) ;
idesc = index_openr ( AmNameIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
AccessMethodOpidIndexScan ( Relation heapRelation ,
Oid claid ,
@ -335,9 +400,10 @@ AccessMethodStrategyIndexScan(Relation heapRelation,
return tuple ;
}
HeapTuple
AttributeNameIndexScan ( Relation heapRelation ,
AttributeRelid NameIndexScan ( Relation heapRelation ,
Oid relid ,
char * attname )
{
@ -357,7 +423,7 @@ AttributeNameIndexScan(Relation heapRelation,
( RegProcedure ) F_NAMEEQ ,
NameGetDatum ( attname ) ) ;
idesc = index_openr ( AttributeNameIndex ) ;
idesc = index_openr ( AttributeRelid NameIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 2 ) ;
index_close ( idesc ) ;
@ -367,7 +433,7 @@ AttributeNameIndexScan(Relation heapRelation,
HeapTuple
AttributeNumIndexScan ( Relation heapRelation ,
AttributeRelid NumIndexScan ( Relation heapRelation ,
Oid relid ,
AttrNumber attnum )
{
@ -387,7 +453,7 @@ AttributeNumIndexScan(Relation heapRelation,
( RegProcedure ) F_INT2EQ ,
Int16GetDatum ( attnum ) ) ;
idesc = index_openr ( AttributeNumIndex ) ;
idesc = index_openr ( AttributeRelid NumIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 2 ) ;
index_close ( idesc ) ;
@ -395,6 +461,92 @@ AttributeNumIndexScan(Relation heapRelation,
return tuple ;
}
HeapTuple
OpclassDeftypeIndexScan ( Relation heapRelation , Oid defType )
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_OIDEQ ,
ObjectIdGetDatum ( defType ) ) ;
idesc = index_openr ( OpclassDeftypeIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
OpclassNameIndexScan ( Relation heapRelation , char * opcName )
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_NAMEEQ ,
PointerGetDatum ( opcName ) ) ;
idesc = index_openr ( OpclassNameIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
GroupNameIndexScan ( Relation heapRelation , char * groName )
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_NAMEEQ ,
PointerGetDatum ( groName ) ) ;
idesc = index_openr ( GroupNameIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
GroupSysidIndexScan ( Relation heapRelation , int4 sysId )
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_INT4EQ ,
Int32GetDatum ( sysId ) ) ;
idesc = index_openr ( GroupSysidIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
IndexRelidIndexScan ( Relation heapRelation , Oid relid )
{
@ -417,9 +569,59 @@ IndexRelidIndexScan(Relation heapRelation, Oid relid)
}
HeapTuple
InheritsRelidSeqnoIndexScan ( Relation heapRelation ,
Oid relid ,
int4 seqno )
{
Relation idesc ;
ScanKeyData skey [ 2 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_OIDEQ ,
ObjectIdGetDatum ( relid ) ) ;
ScanKeyEntryInitialize ( & skey [ 1 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 2 ,
( RegProcedure ) F_INT4EQ ,
Int32GetDatum ( seqno ) ) ;
idesc = index_openr ( InheritsRelidSeqnoIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 2 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
LanguageNameIndexScan ( Relation heapRelation , char * lanName )
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_NAMEEQ ,
PointerGetDatum ( lanName ) ) ;
idesc = index_openr ( LanguageNameIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
ProcedureOidIndexScan ( Relation heapRelation , Oid procId )
Languag eOidIndexScan( Relation heapRelation , Oid lan Id)
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
@ -429,9 +631,102 @@ ProcedureOidIndexScan(Relation heapRelation, Oid procId)
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_OIDEQ ,
ObjectIdGetDatum ( proc Id) ) ;
ObjectIdGetDatum ( lan Id) ) ;
idesc = index_openr ( ProcedureOidIndex ) ;
idesc = index_openr ( LanguageOidIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
ListenerRelnamePidIndexScan ( Relation heapRelation , char * relName , int4 pid )
{
Relation idesc ;
ScanKeyData skey [ 2 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_NAMEEQ ,
PointerGetDatum ( relName ) ) ;
ScanKeyEntryInitialize ( & skey [ 1 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 2 ,
( RegProcedure ) F_INT4EQ ,
Int32GetDatum ( pid ) ) ;
idesc = index_openr ( ListenerRelnamePidIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 2 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
OperatorNameIndexScan ( Relation heapRelation ,
char * oprName ,
Oid oprLeft ,
Oid oprRight ,
char oprKind )
{
Relation idesc ;
ScanKeyData skey [ 4 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_NAMEEQ ,
PointerGetDatum ( oprName ) ) ;
ScanKeyEntryInitialize ( & skey [ 1 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 2 ,
( RegProcedure ) F_OIDEQ ,
ObjectIdGetDatum ( oprLeft ) ) ;
ScanKeyEntryInitialize ( & skey [ 2 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 3 ,
( RegProcedure ) F_OIDEQ ,
ObjectIdGetDatum ( oprRight ) ) ;
ScanKeyEntryInitialize ( & skey [ 3 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 4 ,
( RegProcedure ) F_CHAREQ ,
CharGetDatum ( oprKind ) ) ;
idesc = index_openr ( OperatorNameIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 4 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
OperatorOidIndexScan ( Relation heapRelation , Oid oprId )
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_OIDEQ ,
ObjectIdGetDatum ( oprId ) ) ;
idesc = index_openr ( OperatorOidIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
@ -478,7 +773,7 @@ ProcedureNameIndexScan(Relation heapRelation,
HeapTuple
Typ eOidIndexScan( Relation heapRelation , Oid type Id)
Procedur eOidIndexScan( Relation heapRelation , Oid proc Id)
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
@ -488,9 +783,95 @@ TypeOidIndexScan(Relation heapRelation, Oid typeId)
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_OIDEQ ,
ObjectIdGetDatum ( type Id) ) ;
ObjectIdGetDatum ( proc Id) ) ;
idesc = index_openr ( TypeOidIndex ) ;
idesc = index_openr ( ProcedureOidIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
ClassNameIndexScan ( Relation heapRelation , char * relName )
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_NAMEEQ ,
PointerGetDatum ( relName ) ) ;
idesc = index_openr ( ClassNameIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
ClassOidIndexScan ( 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 ( ClassOidIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
RewriteRulenameIndexScan ( Relation heapRelation , char * ruleName )
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_NAMEEQ ,
PointerGetDatum ( ruleName ) ) ;
idesc = index_openr ( RewriteRulenameIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
RewriteOidIndexScan ( Relation heapRelation , Oid rewriteId )
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_OIDEQ ,
ObjectIdGetDatum ( rewriteId ) ) ;
idesc = index_openr ( RewriteOidIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
@ -522,7 +903,29 @@ TypeNameIndexScan(Relation heapRelation, char *typeName)
HeapTuple
ClassNameIndexScan ( Relation heapRelation , char * relName )
TypeOidIndexScan ( Relation heapRelation , Oid typeId )
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_OIDEQ ,
ObjectIdGetDatum ( typeId ) ) ;
idesc = index_openr ( TypeOidIndex ) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
return tuple ;
}
HeapTuple
ShadowNameIndexScan ( Relation heapRelation , char * useName )
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
@ -532,9 +935,9 @@ ClassNameIndexScan(Relation heapRelation, char *relName)
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_NAMEEQ ,
PointerGetDatum ( rel Name) ) ;
PointerGetDatum ( use Name) ) ;
idesc = index_openr ( Class NameIndex) ;
idesc = index_openr ( Shadow NameIndex) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
@ -543,22 +946,23 @@ ClassNameIndexScan(Relation heapRelation, char *relName)
HeapTuple
ClassO idIndexScan( Relation heapRelation , Oid rel Id)
ShadowSys idIndexScan( Relation heapRelation , int4 sys Id)
{
Relation idesc ;
ScanKeyData skey [ 1 ] ;
HeapTuple tuple ;
ScanKeyEntryInitialize ( & skey [ 0 ] ,
( bits16 ) 0x0 ,
( AttrNumber ) 1 ,
( RegProcedure ) F_OID EQ ,
ObjectIdGetDatum ( rel Id) ) ;
( RegProcedure ) F_INT4 EQ ,
Int32GetDatum ( sys Id) ) ;
idesc = index_openr ( ClassO idIndex) ;
idesc = index_openr ( ShadowSys idIndex) ;
tuple = CatalogIndexFetchTuple ( heapRelation , idesc , skey , 1 ) ;
index_close ( idesc ) ;
return tuple ;
}