Use function to ensure seq dep

velioglu/temp_two_pro
Burak Velioglu 2022-01-28 15:08:17 +03:00
parent 08dcb6c83a
commit 534ee5b6ca
No known key found for this signature in database
GPG Key ID: F6827E620F6549C6
4 changed files with 27 additions and 24 deletions

View File

@ -91,7 +91,7 @@ static void TransferSequenceOwnership(Oid ownedSequenceId, Oid targetRelationId,
char *columnName); char *columnName);
static void InsertMetadataForCitusLocalTable(Oid citusLocalTableId, uint64 shardId, static void InsertMetadataForCitusLocalTable(Oid citusLocalTableId, uint64 shardId,
bool autoConverted); bool autoConverted);
static void FinalizeCitusLocalTableCreation(Oid relationId, List *dependentSequenceList); static void FinalizeCitusLocalTableCreation(Oid relationId);
PG_FUNCTION_INFO_V1(citus_add_local_table_to_metadata); 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 * Ensure that the sequences used in column defaults of the table
* have proper types * have proper types
*/ */
List *attnumList = NIL; EnsureRelationHasCompatibleSequenceTypes(relationId);
List *dependentSequenceList = NIL;
GetDependentSequencesWithRelation(relationId, &attnumList,
&dependentSequenceList, 0);
EnsureDistributedSequencesHaveOneType(relationId, dependentSequenceList,
attnumList);
/* /*
* Ensure dependencies exist as we will create shell table on the other nodes * 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); InsertMetadataForCitusLocalTable(shellRelationId, shardId, autoConverted);
FinalizeCitusLocalTableCreation(shellRelationId, dependentSequenceList); FinalizeCitusLocalTableCreation(shellRelationId);
} }
@ -1230,7 +1225,7 @@ InsertMetadataForCitusLocalTable(Oid citusLocalTableId, uint64 shardId,
* sequences dependent with the table. * sequences dependent with the table.
*/ */
static void static void
FinalizeCitusLocalTableCreation(Oid relationId, List *dependentSequenceList) FinalizeCitusLocalTableCreation(Oid relationId)
{ {
/* /*
* If it is a foreign table, then skip creating citus truncate trigger * If it is a foreign table, then skip creating citus truncate trigger

View File

@ -113,6 +113,9 @@ static void EnsureLocalTableEmptyIfNecessary(Oid relationId, char distributionMe
static bool ShouldLocalTableBeEmpty(Oid relationId, char distributionMethod, bool static bool ShouldLocalTableBeEmpty(Oid relationId, char distributionMethod, bool
viaDeprecatedAPI); viaDeprecatedAPI);
static void EnsureCitusTableCanBeCreated(Oid relationOid); static void EnsureCitusTableCanBeCreated(Oid relationOid);
static void EnsureDistributedSequencesHaveOneType(Oid relationId,
List *dependentSequenceList,
List *attnumList);
static List * GetFKeyCreationCommandsRelationInvolvedWithTableType(Oid relationId, static List * GetFKeyCreationCommandsRelationInvolvedWithTableType(Oid relationId,
int tableTypeFlag); int tableTypeFlag);
static Oid DropFKeysAndUndistributeTable(Oid relationId); 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 * Ensure that the sequences used in column defaults of the table
* have proper types * have proper types
*/ */
List *attnumList = NIL; EnsureRelationHasCompatibleSequenceTypes(relationId);
List *dependentSequenceList = NIL;
GetDependentSequencesWithRelation(relationId, &attnumList, &dependentSequenceList, 0);
EnsureDistributedSequencesHaveOneType(relationId, dependentSequenceList,
attnumList);
/* /*
* distributed tables might have dependencies on different objects, since we create * 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 * EnsureDistributedSequencesHaveOneType first ensures that the type of the column
* in which the sequence is used as default is supported for each sequence in input * 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. * dependentSequenceList, and then alters the sequence type if not the same with the column type.
*/ */
void static void
EnsureDistributedSequencesHaveOneType(Oid relationId, List *dependentSequenceList, EnsureDistributedSequencesHaveOneType(Oid relationId, List *dependentSequenceList,
List *attnumList) List *attnumList)
{ {

View File

@ -1959,12 +1959,7 @@ PostprocessAlterTableStmt(AlterTableStmt *alterTableStatement)
* Before ensuring each dependency exist, update dependent sequences * Before ensuring each dependency exist, update dependent sequences
* types if necessary. * types if necessary.
*/ */
List *attnumList = NIL; EnsureRelationHasCompatibleSequenceTypes(relationId);
List *dependentSequenceList = NIL;
GetDependentSequencesWithRelation(relationId, &attnumList, &dependentSequenceList,
0);
EnsureDistributedSequencesHaveOneType(relationId, dependentSequenceList,
attnumList);
/* changing a relation could introduce new dependencies */ /* changing a relation could introduce new dependencies */
ObjectAddress tableAddress = { 0 }; ObjectAddress tableAddress = { 0 };

View File

@ -288,7 +288,5 @@ extern bool GetNodeDiskSpaceStatsForConnection(MultiConnection *connection,
extern void ExecuteQueryViaSPI(char *query, int SPIOK); extern void ExecuteQueryViaSPI(char *query, int SPIOK);
extern void EnsureSequenceTypeSupported(Oid seqOid, Oid seqTypId, Oid ownerRelationId); extern void EnsureSequenceTypeSupported(Oid seqOid, Oid seqTypId, Oid ownerRelationId);
extern void AlterSequenceType(Oid seqOid, Oid typeOid); extern void AlterSequenceType(Oid seqOid, Oid typeOid);
extern void EnsureDistributedSequencesHaveOneType(Oid relationId, extern void EnsureRelationHasCompatibleSequenceTypes(Oid relationId);
List *dependentSequenceList,
List *attnumList);
#endif /* METADATA_UTILITY_H */ #endif /* METADATA_UTILITY_H */