mirror of https://github.com/citusdata/citus.git
Use function to ensure seq dep
parent
08dcb6c83a
commit
534ee5b6ca
|
@ -91,7 +91,7 @@ static void TransferSequenceOwnership(Oid ownedSequenceId, Oid targetRelationId,
|
|||
char *columnName);
|
||||
static void InsertMetadataForCitusLocalTable(Oid citusLocalTableId, uint64 shardId,
|
||||
bool autoConverted);
|
||||
static void FinalizeCitusLocalTableCreation(Oid relationId, List *dependentSequenceList);
|
||||
static void FinalizeCitusLocalTableCreation(Oid relationId);
|
||||
|
||||
|
||||
PG_FUNCTION_INFO_V1(citus_add_local_table_to_metadata);
|
||||
|
@ -311,12 +311,7 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys, bool autoConve
|
|||
* Ensure that the sequences used in column defaults of the table
|
||||
* have proper types
|
||||
*/
|
||||
List *attnumList = NIL;
|
||||
List *dependentSequenceList = NIL;
|
||||
GetDependentSequencesWithRelation(relationId, &attnumList,
|
||||
&dependentSequenceList, 0);
|
||||
EnsureDistributedSequencesHaveOneType(relationId, dependentSequenceList,
|
||||
attnumList);
|
||||
EnsureRelationHasCompatibleSequenceTypes(relationId);
|
||||
|
||||
/*
|
||||
* Ensure dependencies exist as we will create shell table on the other nodes
|
||||
|
@ -366,7 +361,7 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys, bool autoConve
|
|||
|
||||
InsertMetadataForCitusLocalTable(shellRelationId, shardId, autoConverted);
|
||||
|
||||
FinalizeCitusLocalTableCreation(shellRelationId, dependentSequenceList);
|
||||
FinalizeCitusLocalTableCreation(shellRelationId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1230,7 +1225,7 @@ InsertMetadataForCitusLocalTable(Oid citusLocalTableId, uint64 shardId,
|
|||
* sequences dependent with the table.
|
||||
*/
|
||||
static void
|
||||
FinalizeCitusLocalTableCreation(Oid relationId, List *dependentSequenceList)
|
||||
FinalizeCitusLocalTableCreation(Oid relationId)
|
||||
{
|
||||
/*
|
||||
* If it is a foreign table, then skip creating citus truncate trigger
|
||||
|
|
|
@ -113,6 +113,9 @@ static void EnsureLocalTableEmptyIfNecessary(Oid relationId, char distributionMe
|
|||
static bool ShouldLocalTableBeEmpty(Oid relationId, char distributionMethod, bool
|
||||
viaDeprecatedAPI);
|
||||
static void EnsureCitusTableCanBeCreated(Oid relationOid);
|
||||
static void EnsureDistributedSequencesHaveOneType(Oid relationId,
|
||||
List *dependentSequenceList,
|
||||
List *attnumList);
|
||||
static List * GetFKeyCreationCommandsRelationInvolvedWithTableType(Oid relationId,
|
||||
int tableTypeFlag);
|
||||
static Oid DropFKeysAndUndistributeTable(Oid relationId);
|
||||
|
@ -434,11 +437,7 @@ CreateDistributedTable(Oid relationId, Var *distributionColumn, char distributio
|
|||
* Ensure that the sequences used in column defaults of the table
|
||||
* have proper types
|
||||
*/
|
||||
List *attnumList = NIL;
|
||||
List *dependentSequenceList = NIL;
|
||||
GetDependentSequencesWithRelation(relationId, &attnumList, &dependentSequenceList, 0);
|
||||
EnsureDistributedSequencesHaveOneType(relationId, dependentSequenceList,
|
||||
attnumList);
|
||||
EnsureRelationHasCompatibleSequenceTypes(relationId);
|
||||
|
||||
/*
|
||||
* distributed tables might have dependencies on different objects, since we create
|
||||
|
@ -666,12 +665,28 @@ AlterSequenceType(Oid seqOid, Oid typeOid)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* EnsureRelationHasCompatibleSequenceTypes ensures that sequences used for columns
|
||||
* of the table have compatible types both with the column type on that table and
|
||||
* all other distributed tables' columns they have used for
|
||||
*/
|
||||
void
|
||||
EnsureRelationHasCompatibleSequenceTypes(Oid relationId)
|
||||
{
|
||||
List *attnumList = NIL;
|
||||
List *dependentSequenceList = NIL;
|
||||
|
||||
GetDependentSequencesWithRelation(relationId, &attnumList, &dependentSequenceList, 0);
|
||||
EnsureDistributedSequencesHaveOneType(relationId, dependentSequenceList, attnumList);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* EnsureDistributedSequencesHaveOneType first ensures that the type of the column
|
||||
* in which the sequence is used as default is supported for each sequence in input
|
||||
* dependentSequenceList, and then alters the sequence type if not the same with the column type.
|
||||
*/
|
||||
void
|
||||
static void
|
||||
EnsureDistributedSequencesHaveOneType(Oid relationId, List *dependentSequenceList,
|
||||
List *attnumList)
|
||||
{
|
||||
|
|
|
@ -1959,12 +1959,7 @@ PostprocessAlterTableStmt(AlterTableStmt *alterTableStatement)
|
|||
* Before ensuring each dependency exist, update dependent sequences
|
||||
* types if necessary.
|
||||
*/
|
||||
List *attnumList = NIL;
|
||||
List *dependentSequenceList = NIL;
|
||||
GetDependentSequencesWithRelation(relationId, &attnumList, &dependentSequenceList,
|
||||
0);
|
||||
EnsureDistributedSequencesHaveOneType(relationId, dependentSequenceList,
|
||||
attnumList);
|
||||
EnsureRelationHasCompatibleSequenceTypes(relationId);
|
||||
|
||||
/* changing a relation could introduce new dependencies */
|
||||
ObjectAddress tableAddress = { 0 };
|
||||
|
|
|
@ -288,7 +288,5 @@ extern bool GetNodeDiskSpaceStatsForConnection(MultiConnection *connection,
|
|||
extern void ExecuteQueryViaSPI(char *query, int SPIOK);
|
||||
extern void EnsureSequenceTypeSupported(Oid seqOid, Oid seqTypId, Oid ownerRelationId);
|
||||
extern void AlterSequenceType(Oid seqOid, Oid typeOid);
|
||||
extern void EnsureDistributedSequencesHaveOneType(Oid relationId,
|
||||
List *dependentSequenceList,
|
||||
List *attnumList);
|
||||
extern void EnsureRelationHasCompatibleSequenceTypes(Oid relationId);
|
||||
#endif /* METADATA_UTILITY_H */
|
||||
|
|
Loading…
Reference in New Issue