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:
parent
a69e041d0c
commit
4315e8c23b
|
@ -818,21 +818,15 @@ AddNewAttributeTuples(Oid new_rel_oid,
|
|||
InsertPgAttributeTuple(rel, attr, (Datum) 0, indstate);
|
||||
|
||||
/* Add dependency info */
|
||||
myself.classId = RelationRelationId;
|
||||
myself.objectId = new_rel_oid;
|
||||
myself.objectSubId = i + 1;
|
||||
referenced.classId = TypeRelationId;
|
||||
referenced.objectId = attr->atttypid;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSubSet(myself, RelationRelationId, new_rel_oid, i + 1);
|
||||
ObjectAddressSet(referenced, TypeRelationId, attr->atttypid);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
|
||||
/* The default collation is pinned, so don't bother recording it */
|
||||
if (OidIsValid(attr->attcollation) &&
|
||||
attr->attcollation != DEFAULT_COLLATION_OID)
|
||||
{
|
||||
referenced.classId = CollationRelationId;
|
||||
referenced.objectId = attr->attcollation;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, CollationRelationId, attr->attcollation);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1030,9 +1030,7 @@ index_create(Relation heapRelation,
|
|||
ObjectAddress myself,
|
||||
referenced;
|
||||
|
||||
myself.classId = RelationRelationId;
|
||||
myself.objectId = indexRelationId;
|
||||
myself.objectSubId = 0;
|
||||
ObjectAddressSet(myself, RelationRelationId, indexRelationId);
|
||||
|
||||
if ((flags & INDEX_CREATE_ADD_CONSTRAINT) != 0)
|
||||
{
|
||||
|
@ -1072,12 +1070,10 @@ index_create(Relation heapRelation,
|
|||
{
|
||||
if (indexInfo->ii_IndexAttrNumbers[i] != 0)
|
||||
{
|
||||
referenced.classId = RelationRelationId;
|
||||
referenced.objectId = heapRelationId;
|
||||
referenced.objectSubId = indexInfo->ii_IndexAttrNumbers[i];
|
||||
|
||||
ObjectAddressSubSet(referenced, RelationRelationId,
|
||||
heapRelationId,
|
||||
indexInfo->ii_IndexAttrNumbers[i]);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
|
||||
|
||||
have_simple_col = true;
|
||||
}
|
||||
}
|
||||
|
@ -1090,10 +1086,8 @@ index_create(Relation heapRelation,
|
|||
*/
|
||||
if (!have_simple_col)
|
||||
{
|
||||
referenced.classId = RelationRelationId;
|
||||
referenced.objectId = heapRelationId;
|
||||
referenced.objectSubId = 0;
|
||||
|
||||
ObjectAddressSet(referenced, RelationRelationId,
|
||||
heapRelationId);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
|
||||
}
|
||||
}
|
||||
|
@ -1106,16 +1100,10 @@ index_create(Relation heapRelation,
|
|||
*/
|
||||
if (OidIsValid(parentIndexRelid))
|
||||
{
|
||||
referenced.classId = RelationRelationId;
|
||||
referenced.objectId = parentIndexRelid;
|
||||
referenced.objectSubId = 0;
|
||||
|
||||
ObjectAddressSet(referenced, RelationRelationId, parentIndexRelid);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_PARTITION_PRI);
|
||||
|
||||
referenced.classId = RelationRelationId;
|
||||
referenced.objectId = heapRelationId;
|
||||
referenced.objectSubId = 0;
|
||||
|
||||
ObjectAddressSet(referenced, RelationRelationId, heapRelationId);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_PARTITION_SEC);
|
||||
}
|
||||
|
||||
|
@ -1126,10 +1114,8 @@ index_create(Relation heapRelation,
|
|||
if (OidIsValid(collationObjectId[i]) &&
|
||||
collationObjectId[i] != DEFAULT_COLLATION_OID)
|
||||
{
|
||||
referenced.classId = CollationRelationId;
|
||||
referenced.objectId = collationObjectId[i];
|
||||
referenced.objectSubId = 0;
|
||||
|
||||
ObjectAddressSet(referenced, CollationRelationId,
|
||||
collationObjectId[i]);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
}
|
||||
|
@ -1137,10 +1123,7 @@ index_create(Relation heapRelation,
|
|||
/* Store dependency on operator classes */
|
||||
for (i = 0; i < indexInfo->ii_NumIndexKeyAttrs; i++)
|
||||
{
|
||||
referenced.classId = OperatorClassRelationId;
|
||||
referenced.objectId = classObjectId[i];
|
||||
referenced.objectSubId = 0;
|
||||
|
||||
ObjectAddressSet(referenced, OperatorClassRelationId, classObjectId[i]);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
|
|
|
@ -742,80 +742,62 @@ AggregateCreate(const char *aggName,
|
|||
*/
|
||||
|
||||
/* Depends on transition function */
|
||||
referenced.classId = ProcedureRelationId;
|
||||
referenced.objectId = transfn;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, ProcedureRelationId, transfn);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
|
||||
/* Depends on final function, if any */
|
||||
if (OidIsValid(finalfn))
|
||||
{
|
||||
referenced.classId = ProcedureRelationId;
|
||||
referenced.objectId = finalfn;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, ProcedureRelationId, finalfn);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
/* Depends on combine function, if any */
|
||||
if (OidIsValid(combinefn))
|
||||
{
|
||||
referenced.classId = ProcedureRelationId;
|
||||
referenced.objectId = combinefn;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, ProcedureRelationId, combinefn);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
/* Depends on serialization function, if any */
|
||||
if (OidIsValid(serialfn))
|
||||
{
|
||||
referenced.classId = ProcedureRelationId;
|
||||
referenced.objectId = serialfn;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, ProcedureRelationId, serialfn);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
/* Depends on deserialization function, if any */
|
||||
if (OidIsValid(deserialfn))
|
||||
{
|
||||
referenced.classId = ProcedureRelationId;
|
||||
referenced.objectId = deserialfn;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, ProcedureRelationId, deserialfn);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
/* Depends on forward transition function, if any */
|
||||
if (OidIsValid(mtransfn))
|
||||
{
|
||||
referenced.classId = ProcedureRelationId;
|
||||
referenced.objectId = mtransfn;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, ProcedureRelationId, mtransfn);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
/* Depends on inverse transition function, if any */
|
||||
if (OidIsValid(minvtransfn))
|
||||
{
|
||||
referenced.classId = ProcedureRelationId;
|
||||
referenced.objectId = minvtransfn;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, ProcedureRelationId, minvtransfn);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
/* Depends on final function, if any */
|
||||
if (OidIsValid(mfinalfn))
|
||||
{
|
||||
referenced.classId = ProcedureRelationId;
|
||||
referenced.objectId = mfinalfn;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, ProcedureRelationId, mfinalfn);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
/* Depends on sort operator, if any */
|
||||
if (OidIsValid(sortop))
|
||||
{
|
||||
referenced.classId = OperatorRelationId;
|
||||
referenced.objectId = sortop;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, OperatorRelationId, sortop);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -776,9 +776,7 @@ makeOperatorDependencies(HeapTuple tuple, bool isUpdate)
|
|||
ObjectAddress myself,
|
||||
referenced;
|
||||
|
||||
myself.classId = OperatorRelationId;
|
||||
myself.objectId = oper->oid;
|
||||
myself.objectSubId = 0;
|
||||
ObjectAddressSet(myself, OperatorRelationId, oper->oid);
|
||||
|
||||
/*
|
||||
* If we are updating the operator, delete any existing entries, except
|
||||
|
@ -793,36 +791,28 @@ makeOperatorDependencies(HeapTuple tuple, bool isUpdate)
|
|||
/* Dependency on namespace */
|
||||
if (OidIsValid(oper->oprnamespace))
|
||||
{
|
||||
referenced.classId = NamespaceRelationId;
|
||||
referenced.objectId = oper->oprnamespace;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, NamespaceRelationId, oper->oprnamespace);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
/* Dependency on left type */
|
||||
if (OidIsValid(oper->oprleft))
|
||||
{
|
||||
referenced.classId = TypeRelationId;
|
||||
referenced.objectId = oper->oprleft;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, TypeRelationId, oper->oprleft);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
/* Dependency on right type */
|
||||
if (OidIsValid(oper->oprright))
|
||||
{
|
||||
referenced.classId = TypeRelationId;
|
||||
referenced.objectId = oper->oprright;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, TypeRelationId, oper->oprright);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
/* Dependency on result type */
|
||||
if (OidIsValid(oper->oprresult))
|
||||
{
|
||||
referenced.classId = TypeRelationId;
|
||||
referenced.objectId = oper->oprresult;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, TypeRelationId, oper->oprresult);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
|
@ -838,27 +828,21 @@ makeOperatorDependencies(HeapTuple tuple, bool isUpdate)
|
|||
/* Dependency on implementation function */
|
||||
if (OidIsValid(oper->oprcode))
|
||||
{
|
||||
referenced.classId = ProcedureRelationId;
|
||||
referenced.objectId = oper->oprcode;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, ProcedureRelationId, oper->oprcode);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
/* Dependency on restriction selectivity function */
|
||||
if (OidIsValid(oper->oprrest))
|
||||
{
|
||||
referenced.classId = ProcedureRelationId;
|
||||
referenced.objectId = oper->oprrest;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, ProcedureRelationId, oper->oprrest);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
/* Dependency on join selectivity function */
|
||||
if (OidIsValid(oper->oprjoin))
|
||||
{
|
||||
referenced.classId = ProcedureRelationId;
|
||||
referenced.objectId = oper->oprjoin;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, ProcedureRelationId, oper->oprjoin);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
|
|
|
@ -585,51 +585,37 @@ ProcedureCreate(const char *procedureName,
|
|||
if (is_update)
|
||||
deleteDependencyRecordsFor(ProcedureRelationId, retval, true);
|
||||
|
||||
myself.classId = ProcedureRelationId;
|
||||
myself.objectId = retval;
|
||||
myself.objectSubId = 0;
|
||||
ObjectAddressSet(myself, ProcedureRelationId, retval);
|
||||
|
||||
/* dependency on namespace */
|
||||
referenced.classId = NamespaceRelationId;
|
||||
referenced.objectId = procNamespace;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, NamespaceRelationId, procNamespace);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
|
||||
/* dependency on implementation language */
|
||||
referenced.classId = LanguageRelationId;
|
||||
referenced.objectId = languageObjectId;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, LanguageRelationId, languageObjectId);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
|
||||
/* dependency on return type */
|
||||
referenced.classId = TypeRelationId;
|
||||
referenced.objectId = returnType;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, TypeRelationId, returnType);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
|
||||
/* dependency on transform used by return type, if any */
|
||||
if ((trfid = get_transform_oid(returnType, languageObjectId, true)))
|
||||
{
|
||||
referenced.classId = TransformRelationId;
|
||||
referenced.objectId = trfid;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, TransformRelationId, trfid);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
/* dependency on parameter types */
|
||||
for (i = 0; i < allParamCount; i++)
|
||||
{
|
||||
referenced.classId = TypeRelationId;
|
||||
referenced.objectId = allParams[i];
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, TypeRelationId, allParams[i]);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
|
||||
/* dependency on transform used by parameter type, if any */
|
||||
if ((trfid = get_transform_oid(allParams[i], languageObjectId, true)))
|
||||
{
|
||||
referenced.classId = TransformRelationId;
|
||||
referenced.objectId = trfid;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, TransformRelationId, trfid);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
}
|
||||
|
@ -642,9 +628,7 @@ ProcedureCreate(const char *procedureName,
|
|||
/* dependency on support function, if any */
|
||||
if (OidIsValid(prosupport))
|
||||
{
|
||||
referenced.classId = ProcedureRelationId;
|
||||
referenced.objectId = prosupport;
|
||||
referenced.objectSubId = 0;
|
||||
ObjectAddressSet(referenced, ProcedureRelationId, prosupport);
|
||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue