Exclude reference tables

update-dist-col-for-undistributed-tables
Ahmet Gedemenli 2022-02-17 11:05:37 +03:00
parent 141dc237ce
commit 7519e628e9
1 changed files with 27 additions and 18 deletions

View File

@ -401,10 +401,15 @@ CreateDistributedTable(Oid relationId, Var *distributionColumn, char distributio
*/ */
List *originalForeignKeyRecreationCommands = NIL; List *originalForeignKeyRecreationCommands = NIL;
if (IsCitusTableType(relationId, CITUS_LOCAL_TABLE)) if (IsCitusTableType(relationId, CITUS_LOCAL_TABLE))
{
char *distributionColumnName = NULL;
if (distributionMethod != DISTRIBUTE_BY_NONE)
{ {
/* save the column name to update the distribution column var later */ /* save the column name to update the distribution column var later */
char *distributionColumnName = distributionColumnName =
ColumnToColumnName(relationId, nodeToString(distributionColumn)); ColumnToColumnName(relationId, nodeToString(distributionColumn));
}
/* store foreign key creation commands that relation is involved */ /* store foreign key creation commands that relation is involved */
originalForeignKeyRecreationCommands = originalForeignKeyRecreationCommands =
@ -412,11 +417,14 @@ CreateDistributedTable(Oid relationId, Var *distributionColumn, char distributio
INCLUDE_ALL_TABLE_TYPES); INCLUDE_ALL_TABLE_TYPES);
relationId = DropFKeysAndUndistributeTable(relationId); relationId = DropFKeysAndUndistributeTable(relationId);
/* exclude reference tables */
if (distributionMethod != DISTRIBUTE_BY_NONE)
{
/* /*
* Because we create a new table when undistributing the table, attribute numbers * Because we create a new table when undistributing the table, attribute
* might be changed, because of the dropped columns. To make sure we have the * numbers might be changed, because of the dropped columns. To make sure we
* correct distribution column, we need to build it again, using the original * have the correct distribution column, we need to build it again, using the
* column name that we have saved before. * original column name that we have saved before.
*/ */
Relation relation = try_relation_open(relationId, ExclusiveLock); Relation relation = try_relation_open(relationId, ExclusiveLock);
if (relation == NULL) if (relation == NULL)
@ -430,6 +438,7 @@ CreateDistributedTable(Oid relationId, Var *distributionColumn, char distributio
distributionColumn = BuildDistributionKeyFromColumnName(relation, distributionColumn = BuildDistributionKeyFromColumnName(relation,
distributionColumnName); distributionColumnName);
} }
}
/* /*
* To support foreign keys between reference tables and local tables, * To support foreign keys between reference tables and local tables,