From 427bdf08a076e4c0aac73e67073682279524df74 Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Sun, 16 Jan 2022 16:15:01 +0300 Subject: [PATCH] Use function to get seq dep definition list --- src/backend/distributed/metadata/dependency.c | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/backend/distributed/metadata/dependency.c b/src/backend/distributed/metadata/dependency.c index 8dcba0338..ec8197bf7 100644 --- a/src/backend/distributed/metadata/dependency.c +++ b/src/backend/distributed/metadata/dependency.c @@ -121,6 +121,7 @@ typedef struct ViewDependencyNode }ViewDependencyNode; +static List * GetRelationSequenceDependencyList(Oid relationId); static List * GetRelationTriggerFunctionDepencyList(Oid relationId); static List * GetRelationStatsSchemaDependencyList(Oid relationId); static DependencyDefinition * CreateObjectAddressDependencyDef(Oid classId, Oid objectId); @@ -996,23 +997,11 @@ ExpandCitusSupportedTypes(ObjectAddressCollector *collector, ObjectAddress targe result = list_concat(result, statisticsSchemaDependencyList); /* - * Add the dependent sequences for the relations + * Get the dependent sequences for tables (both as serial columns and + * columns have nextval with existing sequences) and expand dependency list + * with them. */ - List *attnumList = NIL; - List *dependentSequenceList = NIL; - List *sequenceDependencyList = NIL; - - GetDependentSequencesWithRelation(relationId, &attnumList, - &dependentSequenceList, 0); - - ListCell *dependentSequenceCell = NULL; - foreach(dependentSequenceCell, dependentSequenceList) - { - Oid sequenceOid = lfirst_oid(dependentSequenceCell); - DependencyDefinition *dependency = CreateObjectAddressDependencyDef( - RelationRelationId, sequenceOid); - sequenceDependencyList = lappend(sequenceDependencyList, dependency); - } + List *sequenceDependencyList = GetRelationSequenceDependencyList(relationId); result = list_concat(result, sequenceDependencyList); } @@ -1027,6 +1016,32 @@ ExpandCitusSupportedTypes(ObjectAddressCollector *collector, ObjectAddress targe } +/* + * GetRelationSequenceDependencyList returns the sequence dependency definition + * list for the given relation. + */ +static List * +GetRelationSequenceDependencyList(Oid relationId) +{ + List *attnumList = NIL; + List *dependentSequenceList = NIL; + List *sequenceDependencyList = NIL; + + GetDependentSequencesWithRelation(relationId, &attnumList, &dependentSequenceList, 0); + + ListCell *dependentSequenceCell = NULL; + foreach(dependentSequenceCell, dependentSequenceList) + { + Oid sequenceOid = lfirst_oid(dependentSequenceCell); + DependencyDefinition *dependency = CreateObjectAddressDependencyDef( + RelationRelationId, sequenceOid); + sequenceDependencyList = lappend(sequenceDependencyList, dependency); + } + + return sequenceDependencyList; +} + + /* * GetRelationStatsSchemaDependencyList returns a list of DependencyDefinition * objects for the schemas that statistics' of the relation with relationId depends.