Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4315e8c

Browse files
committed
Refactor ObjectAddress field assignments in more places
This is a follow-up commit similar to 68de144, with more places in the backend code simplified with the macros able to assign values to the fields of ObjectAddress. The code paths changed here could be transitioned later into using more grouping when inserting dependency records, simplifying this future work. Author: Daniel Gustafsson, Michael Paquier Discussion: https://postgr.es/m/20190213182737.mxn6hkdxwrzgxk35@alap3.anarazel.de
1 parent a69e041 commit 4315e8c

File tree

6 files changed

+49
-138
lines changed

6 files changed

+49
-138
lines changed

src/backend/catalog/heap.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -818,21 +818,15 @@ AddNewAttributeTuples(Oid new_rel_oid,
818818
InsertPgAttributeTuple(rel, attr, (Datum) 0, indstate);
819819

820820
/* Add dependency info */
821-
myself.classId = RelationRelationId;
822-
myself.objectId = new_rel_oid;
823-
myself.objectSubId = i + 1;
824-
referenced.classId = TypeRelationId;
825-
referenced.objectId = attr->atttypid;
826-
referenced.objectSubId = 0;
821+
ObjectAddressSubSet(myself, RelationRelationId, new_rel_oid, i + 1);
822+
ObjectAddressSet(referenced, TypeRelationId, attr->atttypid);
827823
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
828824

829825
/* The default collation is pinned, so don't bother recording it */
830826
if (OidIsValid(attr->attcollation) &&
831827
attr->attcollation != DEFAULT_COLLATION_OID)
832828
{
833-
referenced.classId = CollationRelationId;
834-
referenced.objectId = attr->attcollation;
835-
referenced.objectSubId = 0;
829+
ObjectAddressSet(referenced, CollationRelationId, attr->attcollation);
836830
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
837831
}
838832
}

src/backend/catalog/index.c

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,9 +1030,7 @@ index_create(Relation heapRelation,
10301030
ObjectAddress myself,
10311031
referenced;
10321032

1033-
myself.classId = RelationRelationId;
1034-
myself.objectId = indexRelationId;
1035-
myself.objectSubId = 0;
1033+
ObjectAddressSet(myself, RelationRelationId, indexRelationId);
10361034

10371035
if ((flags & INDEX_CREATE_ADD_CONSTRAINT) != 0)
10381036
{
@@ -1072,12 +1070,10 @@ index_create(Relation heapRelation,
10721070
{
10731071
if (indexInfo->ii_IndexAttrNumbers[i] != 0)
10741072
{
1075-
referenced.classId = RelationRelationId;
1076-
referenced.objectId = heapRelationId;
1077-
referenced.objectSubId = indexInfo->ii_IndexAttrNumbers[i];
1078-
1073+
ObjectAddressSubSet(referenced, RelationRelationId,
1074+
heapRelationId,
1075+
indexInfo->ii_IndexAttrNumbers[i]);
10791076
recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
1080-
10811077
have_simple_col = true;
10821078
}
10831079
}
@@ -1090,10 +1086,8 @@ index_create(Relation heapRelation,
10901086
*/
10911087
if (!have_simple_col)
10921088
{
1093-
referenced.classId = RelationRelationId;
1094-
referenced.objectId = heapRelationId;
1095-
referenced.objectSubId = 0;
1096-
1089+
ObjectAddressSet(referenced, RelationRelationId,
1090+
heapRelationId);
10971091
recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
10981092
}
10991093
}
@@ -1106,16 +1100,10 @@ index_create(Relation heapRelation,
11061100
*/
11071101
if (OidIsValid(parentIndexRelid))
11081102
{
1109-
referenced.classId = RelationRelationId;
1110-
referenced.objectId = parentIndexRelid;
1111-
referenced.objectSubId = 0;
1112-
1103+
ObjectAddressSet(referenced, RelationRelationId, parentIndexRelid);
11131104
recordDependencyOn(&myself, &referenced, DEPENDENCY_PARTITION_PRI);
11141105

1115-
referenced.classId = RelationRelationId;
1116-
referenced.objectId = heapRelationId;
1117-
referenced.objectSubId = 0;
1118-
1106+
ObjectAddressSet(referenced, RelationRelationId, heapRelationId);
11191107
recordDependencyOn(&myself, &referenced, DEPENDENCY_PARTITION_SEC);
11201108
}
11211109

@@ -1126,21 +1114,16 @@ index_create(Relation heapRelation,
11261114
if (OidIsValid(collationObjectId[i]) &&
11271115
collationObjectId[i] != DEFAULT_COLLATION_OID)
11281116
{
1129-
referenced.classId = CollationRelationId;
1130-
referenced.objectId = collationObjectId[i];
1131-
referenced.objectSubId = 0;
1132-
1117+
ObjectAddressSet(referenced, CollationRelationId,
1118+
collationObjectId[i]);
11331119
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
11341120
}
11351121
}
11361122

11371123
/* Store dependency on operator classes */
11381124
for (i = 0; i < indexInfo->ii_NumIndexKeyAttrs; i++)
11391125
{
1140-
referenced.classId = OperatorClassRelationId;
1141-
referenced.objectId = classObjectId[i];
1142-
referenced.objectSubId = 0;
1143-
1126+
ObjectAddressSet(referenced, OperatorClassRelationId, classObjectId[i]);
11441127
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
11451128
}
11461129

src/backend/catalog/pg_aggregate.c

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -742,80 +742,62 @@ AggregateCreate(const char *aggName,
742742
*/
743743

744744
/* Depends on transition function */
745-
referenced.classId = ProcedureRelationId;
746-
referenced.objectId = transfn;
747-
referenced.objectSubId = 0;
745+
ObjectAddressSet(referenced, ProcedureRelationId, transfn);
748746
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
749747

750748
/* Depends on final function, if any */
751749
if (OidIsValid(finalfn))
752750
{
753-
referenced.classId = ProcedureRelationId;
754-
referenced.objectId = finalfn;
755-
referenced.objectSubId = 0;
751+
ObjectAddressSet(referenced, ProcedureRelationId, finalfn);
756752
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
757753
}
758754

759755
/* Depends on combine function, if any */
760756
if (OidIsValid(combinefn))
761757
{
762-
referenced.classId = ProcedureRelationId;
763-
referenced.objectId = combinefn;
764-
referenced.objectSubId = 0;
758+
ObjectAddressSet(referenced, ProcedureRelationId, combinefn);
765759
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
766760
}
767761

768762
/* Depends on serialization function, if any */
769763
if (OidIsValid(serialfn))
770764
{
771-
referenced.classId = ProcedureRelationId;
772-
referenced.objectId = serialfn;
773-
referenced.objectSubId = 0;
765+
ObjectAddressSet(referenced, ProcedureRelationId, serialfn);
774766
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
775767
}
776768

777769
/* Depends on deserialization function, if any */
778770
if (OidIsValid(deserialfn))
779771
{
780-
referenced.classId = ProcedureRelationId;
781-
referenced.objectId = deserialfn;
782-
referenced.objectSubId = 0;
772+
ObjectAddressSet(referenced, ProcedureRelationId, deserialfn);
783773
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
784774
}
785775

786776
/* Depends on forward transition function, if any */
787777
if (OidIsValid(mtransfn))
788778
{
789-
referenced.classId = ProcedureRelationId;
790-
referenced.objectId = mtransfn;
791-
referenced.objectSubId = 0;
779+
ObjectAddressSet(referenced, ProcedureRelationId, mtransfn);
792780
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
793781
}
794782

795783
/* Depends on inverse transition function, if any */
796784
if (OidIsValid(minvtransfn))
797785
{
798-
referenced.classId = ProcedureRelationId;
799-
referenced.objectId = minvtransfn;
800-
referenced.objectSubId = 0;
786+
ObjectAddressSet(referenced, ProcedureRelationId, minvtransfn);
801787
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
802788
}
803789

804790
/* Depends on final function, if any */
805791
if (OidIsValid(mfinalfn))
806792
{
807-
referenced.classId = ProcedureRelationId;
808-
referenced.objectId = mfinalfn;
809-
referenced.objectSubId = 0;
793+
ObjectAddressSet(referenced, ProcedureRelationId, mfinalfn);
810794
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
811795
}
812796

813797
/* Depends on sort operator, if any */
814798
if (OidIsValid(sortop))
815799
{
816-
referenced.classId = OperatorRelationId;
817-
referenced.objectId = sortop;
818-
referenced.objectSubId = 0;
800+
ObjectAddressSet(referenced, OperatorRelationId, sortop);
819801
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
820802
}
821803

src/backend/catalog/pg_constraint.c

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,7 @@ CreateConstraintEntry(const char *constraintName,
223223

224224
CatalogTupleInsert(conDesc, tup);
225225

226-
conobject.classId = ConstraintRelationId;
227-
conobject.objectId = conOid;
228-
conobject.objectSubId = 0;
226+
ObjectAddressSet(conobject, ConstraintRelationId, conOid);
229227

230228
table_close(conDesc, RowExclusiveLock);
231229

@@ -237,21 +235,18 @@ CreateConstraintEntry(const char *constraintName,
237235
*/
238236
ObjectAddress relobject;
239237

240-
relobject.classId = RelationRelationId;
241-
relobject.objectId = relId;
242238
if (constraintNTotalKeys > 0)
243239
{
244240
for (i = 0; i < constraintNTotalKeys; i++)
245241
{
246-
relobject.objectSubId = constraintKey[i];
247-
242+
ObjectAddressSubSet(relobject, RelationRelationId, relId,
243+
constraintKey[i]);
248244
recordDependencyOn(&conobject, &relobject, DEPENDENCY_AUTO);
249245
}
250246
}
251247
else
252248
{
253-
relobject.objectSubId = 0;
254-
249+
ObjectAddressSet(relobject, RelationRelationId, relId);
255250
recordDependencyOn(&conobject, &relobject, DEPENDENCY_AUTO);
256251
}
257252
}
@@ -263,10 +258,7 @@ CreateConstraintEntry(const char *constraintName,
263258
*/
264259
ObjectAddress domobject;
265260

266-
domobject.classId = TypeRelationId;
267-
domobject.objectId = domainId;
268-
domobject.objectSubId = 0;
269-
261+
ObjectAddressSet(domobject, TypeRelationId, domainId);
270262
recordDependencyOn(&conobject, &domobject, DEPENDENCY_AUTO);
271263
}
272264

@@ -278,21 +270,18 @@ CreateConstraintEntry(const char *constraintName,
278270
*/
279271
ObjectAddress relobject;
280272

281-
relobject.classId = RelationRelationId;
282-
relobject.objectId = foreignRelId;
283273
if (foreignNKeys > 0)
284274
{
285275
for (i = 0; i < foreignNKeys; i++)
286276
{
287-
relobject.objectSubId = foreignKey[i];
288-
277+
ObjectAddressSubSet(relobject, RelationRelationId,
278+
foreignRelId, foreignKey[i]);
289279
recordDependencyOn(&conobject, &relobject, DEPENDENCY_NORMAL);
290280
}
291281
}
292282
else
293283
{
294-
relobject.objectSubId = 0;
295-
284+
ObjectAddressSet(relobject, RelationRelationId, foreignRelId);
296285
recordDependencyOn(&conobject, &relobject, DEPENDENCY_NORMAL);
297286
}
298287
}
@@ -307,10 +296,7 @@ CreateConstraintEntry(const char *constraintName,
307296
*/
308297
ObjectAddress relobject;
309298

310-
relobject.classId = RelationRelationId;
311-
relobject.objectId = indexRelId;
312-
relobject.objectSubId = 0;
313-
299+
ObjectAddressSet(relobject, RelationRelationId, indexRelId);
314300
recordDependencyOn(&conobject, &relobject, DEPENDENCY_NORMAL);
315301
}
316302

@@ -722,9 +708,7 @@ AlterConstraintNamespaces(Oid ownerId, Oid oldNspId,
722708
Form_pg_constraint conform = (Form_pg_constraint) GETSTRUCT(tup);
723709
ObjectAddress thisobj;
724710

725-
thisobj.classId = ConstraintRelationId;
726-
thisobj.objectId = conform->oid;
727-
thisobj.objectSubId = 0;
711+
ObjectAddressSet(thisobj, ConstraintRelationId, conform->oid);
728712

729713
if (object_address_present(&thisobj, objsMoved))
730714
continue;

src/backend/catalog/pg_operator.c

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,7 @@ makeOperatorDependencies(HeapTuple tuple, bool isUpdate)
776776
ObjectAddress myself,
777777
referenced;
778778

779-
myself.classId = OperatorRelationId;
780-
myself.objectId = oper->oid;
781-
myself.objectSubId = 0;
779+
ObjectAddressSet(myself, OperatorRelationId, oper->oid);
782780

783781
/*
784782
* If we are updating the operator, delete any existing entries, except
@@ -793,36 +791,28 @@ makeOperatorDependencies(HeapTuple tuple, bool isUpdate)
793791
/* Dependency on namespace */
794792
if (OidIsValid(oper->oprnamespace))
795793
{
796-
referenced.classId = NamespaceRelationId;
797-
referenced.objectId = oper->oprnamespace;
798-
referenced.objectSubId = 0;
794+
ObjectAddressSet(referenced, NamespaceRelationId, oper->oprnamespace);
799795
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
800796
}
801797

802798
/* Dependency on left type */
803799
if (OidIsValid(oper->oprleft))
804800
{
805-
referenced.classId = TypeRelationId;
806-
referenced.objectId = oper->oprleft;
807-
referenced.objectSubId = 0;
801+
ObjectAddressSet(referenced, TypeRelationId, oper->oprleft);
808802
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
809803
}
810804

811805
/* Dependency on right type */
812806
if (OidIsValid(oper->oprright))
813807
{
814-
referenced.classId = TypeRelationId;
815-
referenced.objectId = oper->oprright;
816-
referenced.objectSubId = 0;
808+
ObjectAddressSet(referenced, TypeRelationId, oper->oprright);
817809
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
818810
}
819811

820812
/* Dependency on result type */
821813
if (OidIsValid(oper->oprresult))
822814
{
823-
referenced.classId = TypeRelationId;
824-
referenced.objectId = oper->oprresult;
825-
referenced.objectSubId = 0;
815+
ObjectAddressSet(referenced, TypeRelationId, oper->oprresult);
826816
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
827817
}
828818

@@ -838,27 +828,21 @@ makeOperatorDependencies(HeapTuple tuple, bool isUpdate)
838828
/* Dependency on implementation function */
839829
if (OidIsValid(oper->oprcode))
840830
{
841-
referenced.classId = ProcedureRelationId;
842-
referenced.objectId = oper->oprcode;
843-
referenced.objectSubId = 0;
831+
ObjectAddressSet(referenced, ProcedureRelationId, oper->oprcode);
844832
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
845833
}
846834

847835
/* Dependency on restriction selectivity function */
848836
if (OidIsValid(oper->oprrest))
849837
{
850-
referenced.classId = ProcedureRelationId;
851-
referenced.objectId = oper->oprrest;
852-
referenced.objectSubId = 0;
838+
ObjectAddressSet(referenced, ProcedureRelationId, oper->oprrest);
853839
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
854840
}
855841

856842
/* Dependency on join selectivity function */
857843
if (OidIsValid(oper->oprjoin))
858844
{
859-
referenced.classId = ProcedureRelationId;
860-
referenced.objectId = oper->oprjoin;
861-
referenced.objectSubId = 0;
845+
ObjectAddressSet(referenced, ProcedureRelationId, oper->oprjoin);
862846
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
863847
}
864848

0 commit comments

Comments
 (0)