@@ -82,6 +82,147 @@ static ObjectAddress get_object_address_opcf(ObjectType objtype, List *objname,
8282 List * objargs , bool missing_ok );
8383static bool object_exists (ObjectAddress address );
8484
85+ /*
86+ * ObjectProperty
87+ *
88+ * This array provides a common part of system object structure; to help
89+ * consolidate routines to handle various kind of object classes.
90+ */
91+ typedef struct
92+ {
93+ Oid class_oid ; /* oid of catalog */
94+ Oid oid_index_oid ; /* oid of index on system oid column */
95+ int oid_catcache_id ; /* id of catcache on system oid column */
96+ } ObjectPropertyType ;
97+
98+ static ObjectPropertyType ObjectProperty [] =
99+ {
100+ {
101+ CastRelationId ,
102+ CastOidIndexId ,
103+ -1
104+ },
105+ {
106+ CollationRelationId ,
107+ CollationOidIndexId ,
108+ COLLOID
109+ },
110+ {
111+ ConstraintRelationId ,
112+ ConstraintOidIndexId ,
113+ CONSTROID
114+ },
115+ {
116+ ConversionRelationId ,
117+ ConversionOidIndexId ,
118+ CONVOID
119+ },
120+ {
121+ DatabaseRelationId ,
122+ DatabaseOidIndexId ,
123+ DATABASEOID
124+ },
125+ {
126+ ExtensionRelationId ,
127+ ExtensionOidIndexId ,
128+ -1
129+ },
130+ {
131+ ForeignDataWrapperRelationId ,
132+ ForeignDataWrapperOidIndexId ,
133+ FOREIGNDATAWRAPPEROID
134+ },
135+ {
136+ ForeignServerRelationId ,
137+ ForeignServerOidIndexId ,
138+ FOREIGNSERVEROID
139+ },
140+ {
141+ ProcedureRelationId ,
142+ ProcedureOidIndexId ,
143+ PROCOID
144+ },
145+ {
146+ LanguageRelationId ,
147+ LanguageOidIndexId ,
148+ LANGOID
149+ },
150+ {
151+ LargeObjectMetadataRelationId ,
152+ LargeObjectMetadataOidIndexId ,
153+ -1
154+ },
155+ {
156+ OperatorClassRelationId ,
157+ OpclassOidIndexId ,
158+ CLAOID
159+ },
160+ {
161+ OperatorRelationId ,
162+ OperatorOidIndexId ,
163+ OPEROID
164+ },
165+ {
166+ OperatorFamilyRelationId ,
167+ OpfamilyOidIndexId ,
168+ OPFAMILYOID
169+ },
170+ {
171+ AuthIdRelationId ,
172+ AuthIdOidIndexId ,
173+ AUTHOID
174+ },
175+ {
176+ RewriteRelationId ,
177+ RewriteOidIndexId ,
178+ -1
179+ },
180+ {
181+ NamespaceRelationId ,
182+ NamespaceOidIndexId ,
183+ NAMESPACEOID
184+ },
185+ {
186+ RelationRelationId ,
187+ ClassOidIndexId ,
188+ RELOID
189+ },
190+ {
191+ TableSpaceRelationId ,
192+ TablespaceOidIndexId ,
193+ TABLESPACEOID ,
194+ },
195+ {
196+ TriggerRelationId ,
197+ TriggerOidIndexId ,
198+ -1
199+ },
200+ {
201+ TSConfigRelationId ,
202+ TSConfigOidIndexId ,
203+ TSCONFIGOID
204+ },
205+ {
206+ TSDictionaryRelationId ,
207+ TSDictionaryOidIndexId ,
208+ TSDICTOID
209+ },
210+ {
211+ TSParserRelationId ,
212+ TSParserOidIndexId ,
213+ TSPARSEROID
214+ },
215+ {
216+ TSTemplateRelationId ,
217+ TSTemplateOidIndexId ,
218+ TSTEMPLATEOID
219+ },
220+ {
221+ TypeRelationId ,
222+ TypeOidIndexId ,
223+ TYPEOID
224+ }
225+ };
85226
86227/*
87228 * Translate an object name and arguments (as passed by the parser) to an
@@ -448,7 +589,7 @@ get_relation_by_qualified_name(ObjectType objtype, List *objname,
448589 break ;
449590 }
450591
451- /* Done */
592+ /* Done. */
452593 address .objectId = RelationGetRelid (relation );
453594 * relp = relation ;
454595
@@ -697,99 +838,33 @@ object_exists(ObjectAddress address)
697838 }
698839 return found ;
699840 }
700-
701- /*
702- * For object types that have a relevant syscache, we use it; for
703- * everything else, we'll have to do an index-scan. This switch sets
704- * either the cache to be used for the syscache lookup, or the index to be
705- * used for the index scan.
706- */
707- switch (address .classId )
841+ else
708842 {
709- case RelationRelationId :
710- cache = RELOID ;
711- break ;
712- case RewriteRelationId :
713- indexoid = RewriteOidIndexId ;
714- break ;
715- case TriggerRelationId :
716- indexoid = TriggerOidIndexId ;
717- break ;
718- case ConstraintRelationId :
719- cache = CONSTROID ;
720- break ;
721- case DatabaseRelationId :
722- cache = DATABASEOID ;
723- break ;
724- case TableSpaceRelationId :
725- cache = TABLESPACEOID ;
726- break ;
727- case AuthIdRelationId :
728- cache = AUTHOID ;
729- break ;
730- case NamespaceRelationId :
731- cache = NAMESPACEOID ;
732- break ;
733- case LanguageRelationId :
734- cache = LANGOID ;
735- break ;
736- case TypeRelationId :
737- cache = TYPEOID ;
738- break ;
739- case ProcedureRelationId :
740- cache = PROCOID ;
741- break ;
742- case OperatorRelationId :
743- cache = OPEROID ;
744- break ;
745- case CollationRelationId :
746- cache = COLLOID ;
747- break ;
748- case ConversionRelationId :
749- cache = CONVOID ;
750- break ;
751- case OperatorClassRelationId :
752- cache = CLAOID ;
753- break ;
754- case OperatorFamilyRelationId :
755- cache = OPFAMILYOID ;
756- break ;
757- case LargeObjectRelationId :
843+ int index ;
758844
759- /*
760- * Weird backward compatibility hack: ObjectAddress notation uses
761- * LargeObjectRelationId for large objects, but since PostgreSQL
762- * 9.0, the relevant catalog is actually
763- * LargeObjectMetadataRelationId.
764- */
845+ /*
846+ * Weird backward compatibility hack: ObjectAddress notation uses
847+ * LargeObjectRelationId for large objects, but since PostgreSQL
848+ * 9.0, the relevant catalog is actually LargeObjectMetadataRelationId.
849+ */
850+ if ( address . classId == LargeObjectRelationId )
765851 address .classId = LargeObjectMetadataRelationId ;
766- indexoid = LargeObjectMetadataOidIndexId ;
767- break ;
768- case CastRelationId :
769- indexoid = CastOidIndexId ;
770- break ;
771- case ForeignDataWrapperRelationId :
772- cache = FOREIGNDATAWRAPPEROID ;
773- break ;
774- case ForeignServerRelationId :
775- cache = FOREIGNSERVEROID ;
776- break ;
777- case TSParserRelationId :
778- cache = TSPARSEROID ;
779- break ;
780- case TSDictionaryRelationId :
781- cache = TSDICTOID ;
782- break ;
783- case TSTemplateRelationId :
784- cache = TSTEMPLATEOID ;
785- break ;
786- case TSConfigRelationId :
787- cache = TSCONFIGOID ;
788- break ;
789- case ExtensionRelationId :
790- indexoid = ExtensionOidIndexId ;
791- break ;
792- default :
852+
853+ /*
854+ * For object types that have a relevant syscache, we use it; for
855+ * everything else, we'll have to do an index-scan. Search the
856+ * ObjectProperty array to find out which it is.
857+ */
858+ for (index = 0 ; index < lengthof (ObjectProperty ); index ++ )
859+ {
860+ if (ObjectProperty [index ].class_oid == address .classId )
861+ {
862+ cache = ObjectProperty [index ].oid_catcache_id ;
863+ indexoid = ObjectProperty [index ].oid_index_oid ;
864+ break ;
865+ }
866+ }
867+ if (index == lengthof (ObjectProperty ))
793868 elog (ERROR , "unrecognized classid: %u" , address .classId );
794869 }
795870
0 commit comments