mirror of https://github.com/citusdata/citus.git
Move 2 functions to correct files (#7000)
Followup item from https://github.com/citusdata/citus/pull/6933#discussion_r1217896933pull/6936/head^2
parent
b96d3171a2
commit
5acbd735ca
|
@ -361,6 +361,43 @@ worker_change_sequence_dependency(PG_FUNCTION_ARGS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DropFKeysAndUndistributeTable drops all foreign keys that relation with
|
||||||
|
* relationId is involved then undistributes it.
|
||||||
|
* Note that as UndistributeTable changes relationId of relation, this
|
||||||
|
* function also returns new relationId of relation.
|
||||||
|
* Also note that callers are responsible for storing & recreating foreign
|
||||||
|
* keys to be dropped if needed.
|
||||||
|
*/
|
||||||
|
Oid
|
||||||
|
DropFKeysAndUndistributeTable(Oid relationId)
|
||||||
|
{
|
||||||
|
DropFKeysRelationInvolvedWithTableType(relationId, INCLUDE_ALL_TABLE_TYPES);
|
||||||
|
|
||||||
|
/* store them before calling UndistributeTable as it changes relationId */
|
||||||
|
char *relationName = get_rel_name(relationId);
|
||||||
|
Oid schemaId = get_rel_namespace(relationId);
|
||||||
|
|
||||||
|
/* suppress notices messages not to be too verbose */
|
||||||
|
TableConversionParameters params = {
|
||||||
|
.relationId = relationId,
|
||||||
|
.cascadeViaForeignKeys = false,
|
||||||
|
.suppressNoticeMessages = true
|
||||||
|
};
|
||||||
|
UndistributeTable(¶ms);
|
||||||
|
|
||||||
|
Oid newRelationId = get_relname_relid(relationName, schemaId);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We don't expect this to happen but to be on the safe side let's error
|
||||||
|
* out here.
|
||||||
|
*/
|
||||||
|
EnsureRelationExists(newRelationId);
|
||||||
|
|
||||||
|
return newRelationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* UndistributeTables undistributes given relations. It first collects all foreign keys
|
* UndistributeTables undistributes given relations. It first collects all foreign keys
|
||||||
* to recreate them after the undistribution. Then, drops the foreign keys and
|
* to recreate them after the undistribution. Then, drops the foreign keys and
|
||||||
|
|
|
@ -1571,85 +1571,6 @@ EnsureDistributedSequencesHaveOneType(Oid relationId, List *seqInfoList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* GetFKeyCreationCommandsRelationInvolvedWithTableType returns a list of DDL
|
|
||||||
* commands to recreate the foreign keys that relation with relationId is involved
|
|
||||||
* with given table type.
|
|
||||||
*/
|
|
||||||
List *
|
|
||||||
GetFKeyCreationCommandsRelationInvolvedWithTableType(Oid relationId, int tableTypeFlag)
|
|
||||||
{
|
|
||||||
int referencingFKeysFlag = INCLUDE_REFERENCING_CONSTRAINTS |
|
|
||||||
tableTypeFlag;
|
|
||||||
List *referencingFKeyCreationCommands =
|
|
||||||
GetForeignConstraintCommandsInternal(relationId, referencingFKeysFlag);
|
|
||||||
|
|
||||||
/* already captured self referencing foreign keys, so use EXCLUDE_SELF_REFERENCES */
|
|
||||||
int referencedFKeysFlag = INCLUDE_REFERENCED_CONSTRAINTS |
|
|
||||||
EXCLUDE_SELF_REFERENCES |
|
|
||||||
tableTypeFlag;
|
|
||||||
List *referencedFKeyCreationCommands =
|
|
||||||
GetForeignConstraintCommandsInternal(relationId, referencedFKeysFlag);
|
|
||||||
return list_concat(referencingFKeyCreationCommands, referencedFKeyCreationCommands);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* DropFKeysAndUndistributeTable drops all foreign keys that relation with
|
|
||||||
* relationId is involved then undistributes it.
|
|
||||||
* Note that as UndistributeTable changes relationId of relation, this
|
|
||||||
* function also returns new relationId of relation.
|
|
||||||
* Also note that callers are responsible for storing & recreating foreign
|
|
||||||
* keys to be dropped if needed.
|
|
||||||
*/
|
|
||||||
Oid
|
|
||||||
DropFKeysAndUndistributeTable(Oid relationId)
|
|
||||||
{
|
|
||||||
DropFKeysRelationInvolvedWithTableType(relationId, INCLUDE_ALL_TABLE_TYPES);
|
|
||||||
|
|
||||||
/* store them before calling UndistributeTable as it changes relationId */
|
|
||||||
char *relationName = get_rel_name(relationId);
|
|
||||||
Oid schemaId = get_rel_namespace(relationId);
|
|
||||||
|
|
||||||
/* suppress notices messages not to be too verbose */
|
|
||||||
TableConversionParameters params = {
|
|
||||||
.relationId = relationId,
|
|
||||||
.cascadeViaForeignKeys = false,
|
|
||||||
.suppressNoticeMessages = true
|
|
||||||
};
|
|
||||||
UndistributeTable(¶ms);
|
|
||||||
|
|
||||||
Oid newRelationId = get_relname_relid(relationName, schemaId);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We don't expect this to happen but to be on the safe side let's error
|
|
||||||
* out here.
|
|
||||||
*/
|
|
||||||
EnsureRelationExists(newRelationId);
|
|
||||||
|
|
||||||
return newRelationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* DropFKeysRelationInvolvedWithTableType drops foreign keys that relation
|
|
||||||
* with relationId is involved with given table type.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
DropFKeysRelationInvolvedWithTableType(Oid relationId, int tableTypeFlag)
|
|
||||||
{
|
|
||||||
int referencingFKeysFlag = INCLUDE_REFERENCING_CONSTRAINTS |
|
|
||||||
tableTypeFlag;
|
|
||||||
DropRelationForeignKeys(relationId, referencingFKeysFlag);
|
|
||||||
|
|
||||||
/* already captured self referencing foreign keys, so use EXCLUDE_SELF_REFERENCES */
|
|
||||||
int referencedFKeysFlag = INCLUDE_REFERENCED_CONSTRAINTS |
|
|
||||||
EXCLUDE_SELF_REFERENCES |
|
|
||||||
tableTypeFlag;
|
|
||||||
DropRelationForeignKeys(relationId, referencedFKeysFlag);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DecideDistTableReplicationModel function decides which replication model should be
|
* DecideDistTableReplicationModel function decides which replication model should be
|
||||||
* used for a distributed table depending on given distribution configuration.
|
* used for a distributed table depending on given distribution configuration.
|
||||||
|
|
|
@ -896,6 +896,48 @@ GetForeignConstraintCommandsInternal(Oid relationId, int flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GetFKeyCreationCommandsRelationInvolvedWithTableType returns a list of DDL
|
||||||
|
* commands to recreate the foreign keys that relation with relationId is involved
|
||||||
|
* with given table type.
|
||||||
|
*/
|
||||||
|
List *
|
||||||
|
GetFKeyCreationCommandsRelationInvolvedWithTableType(Oid relationId, int tableTypeFlag)
|
||||||
|
{
|
||||||
|
int referencingFKeysFlag = INCLUDE_REFERENCING_CONSTRAINTS |
|
||||||
|
tableTypeFlag;
|
||||||
|
List *referencingFKeyCreationCommands =
|
||||||
|
GetForeignConstraintCommandsInternal(relationId, referencingFKeysFlag);
|
||||||
|
|
||||||
|
/* already captured self referencing foreign keys, so use EXCLUDE_SELF_REFERENCES */
|
||||||
|
int referencedFKeysFlag = INCLUDE_REFERENCED_CONSTRAINTS |
|
||||||
|
EXCLUDE_SELF_REFERENCES |
|
||||||
|
tableTypeFlag;
|
||||||
|
List *referencedFKeyCreationCommands =
|
||||||
|
GetForeignConstraintCommandsInternal(relationId, referencedFKeysFlag);
|
||||||
|
return list_concat(referencingFKeyCreationCommands, referencedFKeyCreationCommands);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DropFKeysRelationInvolvedWithTableType drops foreign keys that relation
|
||||||
|
* with relationId is involved with given table type.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
DropFKeysRelationInvolvedWithTableType(Oid relationId, int tableTypeFlag)
|
||||||
|
{
|
||||||
|
int referencingFKeysFlag = INCLUDE_REFERENCING_CONSTRAINTS |
|
||||||
|
tableTypeFlag;
|
||||||
|
DropRelationForeignKeys(relationId, referencingFKeysFlag);
|
||||||
|
|
||||||
|
/* already captured self referencing foreign keys, so use EXCLUDE_SELF_REFERENCES */
|
||||||
|
int referencedFKeysFlag = INCLUDE_REFERENCED_CONSTRAINTS |
|
||||||
|
EXCLUDE_SELF_REFERENCES |
|
||||||
|
tableTypeFlag;
|
||||||
|
DropRelationForeignKeys(relationId, referencedFKeysFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* HasForeignKeyWithLocalTable returns true if relation has foreign key
|
* HasForeignKeyWithLocalTable returns true if relation has foreign key
|
||||||
* relationship with a local table.
|
* relationship with a local table.
|
||||||
|
|
Loading…
Reference in New Issue