1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-24 00:23:06 +03:00

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
This commit is contained in:
Michael Paquier
2020-07-01 17:03:50 +09:00
parent a69e041d0c
commit 4315e8c23b
6 changed files with 49 additions and 138 deletions

View File

@@ -223,9 +223,7 @@ CreateConstraintEntry(const char *constraintName,
CatalogTupleInsert(conDesc, tup);
conobject.classId = ConstraintRelationId;
conobject.objectId = conOid;
conobject.objectSubId = 0;
ObjectAddressSet(conobject, ConstraintRelationId, conOid);
table_close(conDesc, RowExclusiveLock);
@@ -237,21 +235,18 @@ CreateConstraintEntry(const char *constraintName,
*/
ObjectAddress relobject;
relobject.classId = RelationRelationId;
relobject.objectId = relId;
if (constraintNTotalKeys > 0)
{
for (i = 0; i < constraintNTotalKeys; i++)
{
relobject.objectSubId = constraintKey[i];
ObjectAddressSubSet(relobject, RelationRelationId, relId,
constraintKey[i]);
recordDependencyOn(&conobject, &relobject, DEPENDENCY_AUTO);
}
}
else
{
relobject.objectSubId = 0;
ObjectAddressSet(relobject, RelationRelationId, relId);
recordDependencyOn(&conobject, &relobject, DEPENDENCY_AUTO);
}
}
@@ -263,10 +258,7 @@ CreateConstraintEntry(const char *constraintName,
*/
ObjectAddress domobject;
domobject.classId = TypeRelationId;
domobject.objectId = domainId;
domobject.objectSubId = 0;
ObjectAddressSet(domobject, TypeRelationId, domainId);
recordDependencyOn(&conobject, &domobject, DEPENDENCY_AUTO);
}
@@ -278,21 +270,18 @@ CreateConstraintEntry(const char *constraintName,
*/
ObjectAddress relobject;
relobject.classId = RelationRelationId;
relobject.objectId = foreignRelId;
if (foreignNKeys > 0)
{
for (i = 0; i < foreignNKeys; i++)
{
relobject.objectSubId = foreignKey[i];
ObjectAddressSubSet(relobject, RelationRelationId,
foreignRelId, foreignKey[i]);
recordDependencyOn(&conobject, &relobject, DEPENDENCY_NORMAL);
}
}
else
{
relobject.objectSubId = 0;
ObjectAddressSet(relobject, RelationRelationId, foreignRelId);
recordDependencyOn(&conobject, &relobject, DEPENDENCY_NORMAL);
}
}
@@ -307,10 +296,7 @@ CreateConstraintEntry(const char *constraintName,
*/
ObjectAddress relobject;
relobject.classId = RelationRelationId;
relobject.objectId = indexRelId;
relobject.objectSubId = 0;
ObjectAddressSet(relobject, RelationRelationId, indexRelId);
recordDependencyOn(&conobject, &relobject, DEPENDENCY_NORMAL);
}
@@ -722,9 +708,7 @@ AlterConstraintNamespaces(Oid ownerId, Oid oldNspId,
Form_pg_constraint conform = (Form_pg_constraint) GETSTRUCT(tup);
ObjectAddress thisobj;
thisobj.classId = ConstraintRelationId;
thisobj.objectId = conform->oid;
thisobj.objectSubId = 0;
ObjectAddressSet(thisobj, ConstraintRelationId, conform->oid);
if (object_address_present(&thisobj, objsMoved))
continue;