Use function to get seq dep definition list

velioglu/wo_seq_test_1
Burak Velioglu 2022-01-16 16:15:01 +03:00
parent ef7ddef07d
commit 427bdf08a0
No known key found for this signature in database
GPG Key ID: F6827E620F6549C6
1 changed files with 31 additions and 16 deletions

View File

@ -121,6 +121,7 @@ typedef struct ViewDependencyNode
}ViewDependencyNode; }ViewDependencyNode;
static List * GetRelationSequenceDependencyList(Oid relationId);
static List * GetRelationTriggerFunctionDepencyList(Oid relationId); static List * GetRelationTriggerFunctionDepencyList(Oid relationId);
static List * GetRelationStatsSchemaDependencyList(Oid relationId); static List * GetRelationStatsSchemaDependencyList(Oid relationId);
static DependencyDefinition * CreateObjectAddressDependencyDef(Oid classId, Oid objectId); static DependencyDefinition * CreateObjectAddressDependencyDef(Oid classId, Oid objectId);
@ -996,23 +997,11 @@ ExpandCitusSupportedTypes(ObjectAddressCollector *collector, ObjectAddress targe
result = list_concat(result, statisticsSchemaDependencyList); 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 *sequenceDependencyList = GetRelationSequenceDependencyList(relationId);
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);
}
result = list_concat(result, sequenceDependencyList); 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 * GetRelationStatsSchemaDependencyList returns a list of DependencyDefinition
* objects for the schemas that statistics' of the relation with relationId depends. * objects for the schemas that statistics' of the relation with relationId depends.