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

Commit 68de144

Browse files
committed
Refactor ObjectAddress field assignments for type dependencies
The logic used to build the set of dependencies needed for a type is rather repetitive with direct assignments for each ObjectAddress field. This refactors the code to use the macro ObjectAddressSet() instead, to do the same work. There are more areas of the backend code that could use this macro, but these are left for a follow-up patch that will partially rework the way dependencies are recorded as well. Type dependencies are left out of the follow-up patch, so they are refactored separately here. Extracted from a larger patch by the same author. Author: Daniel Gustafsson Discussion: https://potgr.es/m/20190213182737.mxn6hkdxwrzgxk35@alap3.anarazel.de
1 parent 96879a0 commit 68de144

File tree

1 file changed

+14
-39
lines changed

1 file changed

+14
-39
lines changed

src/backend/catalog/pg_type.c

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,7 @@ GenerateTypeDependencies(HeapTuple typeTuple,
579579
deleteSharedDependencyRecordsFor(TypeRelationId, typeObjectId, 0);
580580
}
581581

582-
myself.classId = TypeRelationId;
583-
myself.objectId = typeObjectId;
584-
myself.objectSubId = 0;
582+
ObjectAddressSet(myself, TypeRelationId, typeObjectId);
585583

586584
/*
587585
* Make dependencies on namespace, owner, ACL, extension.
@@ -591,9 +589,8 @@ GenerateTypeDependencies(HeapTuple typeTuple,
591589
*/
592590
if (!isDependentType)
593591
{
594-
referenced.classId = NamespaceRelationId;
595-
referenced.objectId = typeForm->typnamespace;
596-
referenced.objectSubId = 0;
592+
ObjectAddressSet(referenced, NamespaceRelationId,
593+
typeForm->typnamespace);
597594
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
598595

599596
recordDependencyOnOwner(TypeRelationId, typeObjectId,
@@ -608,57 +605,43 @@ GenerateTypeDependencies(HeapTuple typeTuple,
608605
/* Normal dependencies on the I/O functions */
609606
if (OidIsValid(typeForm->typinput))
610607
{
611-
referenced.classId = ProcedureRelationId;
612-
referenced.objectId = typeForm->typinput;
613-
referenced.objectSubId = 0;
608+
ObjectAddressSet(referenced, ProcedureRelationId, typeForm->typinput);
614609
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
615610
}
616611

617612
if (OidIsValid(typeForm->typoutput))
618613
{
619-
referenced.classId = ProcedureRelationId;
620-
referenced.objectId = typeForm->typoutput;
621-
referenced.objectSubId = 0;
614+
ObjectAddressSet(referenced, ProcedureRelationId, typeForm->typoutput);
622615
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
623616
}
624617

625618
if (OidIsValid(typeForm->typreceive))
626619
{
627-
referenced.classId = ProcedureRelationId;
628-
referenced.objectId = typeForm->typreceive;
629-
referenced.objectSubId = 0;
620+
ObjectAddressSet(referenced, ProcedureRelationId, typeForm->typreceive);
630621
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
631622
}
632623

633624
if (OidIsValid(typeForm->typsend))
634625
{
635-
referenced.classId = ProcedureRelationId;
636-
referenced.objectId = typeForm->typsend;
637-
referenced.objectSubId = 0;
626+
ObjectAddressSet(referenced, ProcedureRelationId, typeForm->typsend);
638627
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
639628
}
640629

641630
if (OidIsValid(typeForm->typmodin))
642631
{
643-
referenced.classId = ProcedureRelationId;
644-
referenced.objectId = typeForm->typmodin;
645-
referenced.objectSubId = 0;
632+
ObjectAddressSet(referenced, ProcedureRelationId, typeForm->typmodin);
646633
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
647634
}
648635

649636
if (OidIsValid(typeForm->typmodout))
650637
{
651-
referenced.classId = ProcedureRelationId;
652-
referenced.objectId = typeForm->typmodout;
653-
referenced.objectSubId = 0;
638+
ObjectAddressSet(referenced, ProcedureRelationId, typeForm->typmodout);
654639
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
655640
}
656641

657642
if (OidIsValid(typeForm->typanalyze))
658643
{
659-
referenced.classId = ProcedureRelationId;
660-
referenced.objectId = typeForm->typanalyze;
661-
referenced.objectSubId = 0;
644+
ObjectAddressSet(referenced, ProcedureRelationId, typeForm->typanalyze);
662645
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
663646
}
664647

@@ -673,9 +656,7 @@ GenerateTypeDependencies(HeapTuple typeTuple,
673656
*/
674657
if (OidIsValid(typeForm->typrelid))
675658
{
676-
referenced.classId = RelationRelationId;
677-
referenced.objectId = typeForm->typrelid;
678-
referenced.objectSubId = 0;
659+
ObjectAddressSet(referenced, RelationRelationId, typeForm->typrelid);
679660

680661
if (relationKind != RELKIND_COMPOSITE_TYPE)
681662
recordDependencyOn(&myself, &referenced, DEPENDENCY_INTERNAL);
@@ -690,19 +671,15 @@ GenerateTypeDependencies(HeapTuple typeTuple,
690671
*/
691672
if (OidIsValid(typeForm->typelem))
692673
{
693-
referenced.classId = TypeRelationId;
694-
referenced.objectId = typeForm->typelem;
695-
referenced.objectSubId = 0;
674+
ObjectAddressSet(referenced, TypeRelationId, typeForm->typelem);
696675
recordDependencyOn(&myself, &referenced,
697676
isImplicitArray ? DEPENDENCY_INTERNAL : DEPENDENCY_NORMAL);
698677
}
699678

700679
/* Normal dependency from a domain to its base type. */
701680
if (OidIsValid(typeForm->typbasetype))
702681
{
703-
referenced.classId = TypeRelationId;
704-
referenced.objectId = typeForm->typbasetype;
705-
referenced.objectSubId = 0;
682+
ObjectAddressSet(referenced, TypeRelationId, typeForm->typbasetype);
706683
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
707684
}
708685

@@ -711,9 +688,7 @@ GenerateTypeDependencies(HeapTuple typeTuple,
711688
if (OidIsValid(typeForm->typcollation) &&
712689
typeForm->typcollation != DEFAULT_COLLATION_OID)
713690
{
714-
referenced.classId = CollationRelationId;
715-
referenced.objectId = typeForm->typcollation;
716-
referenced.objectSubId = 0;
691+
ObjectAddressSet(referenced, CollationRelationId, typeForm->typcollation);
717692
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
718693
}
719694

0 commit comments

Comments
 (0)