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

Commitfa351d5

Browse files
committed
Replace hardcoded switch in object_exists() with a lookup table.
There's no particular advantage to this change on its face; indeed,it's possible that this might be slightly slower than the old way.But it makes this information more easily accessible to otherfunctions, and therefore paves the way for future code consolidation.Performance isn't critical here, so there's no need to be smart abouthow we do the search.This is a heavily cut-down version of a patch from KaiGai Kohei,with several fixes by me. Additional review from Dimitri Fontaine.
1 parente76bcab commitfa351d5

File tree

1 file changed

+166
-91
lines changed

1 file changed

+166
-91
lines changed

‎src/backend/catalog/objectaddress.c

Lines changed: 166 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,147 @@ static ObjectAddress get_object_address_opcf(ObjectType objtype, List *objname,
8282
List*objargs,boolmissing_ok);
8383
staticboolobject_exists(ObjectAddressaddress);
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+
typedefstruct
92+
{
93+
Oidclass_oid;/* oid of catalog */
94+
Oidoid_index_oid;/* oid of index on system oid column */
95+
intoid_catcache_id;/* id of catcache on system oid column */
96+
}ObjectPropertyType;
97+
98+
staticObjectPropertyTypeObjectProperty[]=
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
returnfound;
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-
caseRelationRelationId:
710-
cache=RELOID;
711-
break;
712-
caseRewriteRelationId:
713-
indexoid=RewriteOidIndexId;
714-
break;
715-
caseTriggerRelationId:
716-
indexoid=TriggerOidIndexId;
717-
break;
718-
caseConstraintRelationId:
719-
cache=CONSTROID;
720-
break;
721-
caseDatabaseRelationId:
722-
cache=DATABASEOID;
723-
break;
724-
caseTableSpaceRelationId:
725-
cache=TABLESPACEOID;
726-
break;
727-
caseAuthIdRelationId:
728-
cache=AUTHOID;
729-
break;
730-
caseNamespaceRelationId:
731-
cache=NAMESPACEOID;
732-
break;
733-
caseLanguageRelationId:
734-
cache=LANGOID;
735-
break;
736-
caseTypeRelationId:
737-
cache=TYPEOID;
738-
break;
739-
caseProcedureRelationId:
740-
cache=PROCOID;
741-
break;
742-
caseOperatorRelationId:
743-
cache=OPEROID;
744-
break;
745-
caseCollationRelationId:
746-
cache=COLLOID;
747-
break;
748-
caseConversionRelationId:
749-
cache=CONVOID;
750-
break;
751-
caseOperatorClassRelationId:
752-
cache=CLAOID;
753-
break;
754-
caseOperatorFamilyRelationId:
755-
cache=OPFAMILYOID;
756-
break;
757-
caseLargeObjectRelationId:
843+
intindex;
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-
caseCastRelationId:
769-
indexoid=CastOidIndexId;
770-
break;
771-
caseForeignDataWrapperRelationId:
772-
cache=FOREIGNDATAWRAPPEROID;
773-
break;
774-
caseForeignServerRelationId:
775-
cache=FOREIGNSERVEROID;
776-
break;
777-
caseTSParserRelationId:
778-
cache=TSPARSEROID;
779-
break;
780-
caseTSDictionaryRelationId:
781-
cache=TSDICTOID;
782-
break;
783-
caseTSTemplateRelationId:
784-
cache=TSTEMPLATEOID;
785-
break;
786-
caseTSConfigRelationId:
787-
cache=TSCONFIGOID;
788-
break;
789-
caseExtensionRelationId:
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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp