From 7519e628e9bba452b425e360e89a646280dbdb8b Mon Sep 17 00:00:00 2001 From: Ahmet Gedemenli Date: Thu, 17 Feb 2022 11:05:37 +0300 Subject: [PATCH] Exclude reference tables --- .../commands/create_distributed_table.c | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/backend/distributed/commands/create_distributed_table.c b/src/backend/distributed/commands/create_distributed_table.c index 5a6c0149f..e0c767474 100644 --- a/src/backend/distributed/commands/create_distributed_table.c +++ b/src/backend/distributed/commands/create_distributed_table.c @@ -402,9 +402,14 @@ CreateDistributedTable(Oid relationId, Var *distributionColumn, char distributio List *originalForeignKeyRecreationCommands = NIL; if (IsCitusTableType(relationId, CITUS_LOCAL_TABLE)) { - /* save the column name to update the distribution column var later */ - char *distributionColumnName = - ColumnToColumnName(relationId, nodeToString(distributionColumn)); + char *distributionColumnName = NULL; + + if (distributionMethod != DISTRIBUTE_BY_NONE) + { + /* save the column name to update the distribution column var later */ + distributionColumnName = + ColumnToColumnName(relationId, nodeToString(distributionColumn)); + } /* store foreign key creation commands that relation is involved */ originalForeignKeyRecreationCommands = @@ -412,23 +417,27 @@ CreateDistributedTable(Oid relationId, Var *distributionColumn, char distributio INCLUDE_ALL_TABLE_TYPES); relationId = DropFKeysAndUndistributeTable(relationId); - /* - * Because we create a new table when undistributing the table, attribute numbers - * might be changed, because of the dropped columns. To make sure we have the - * correct distribution column, we need to build it again, using the original - * column name that we have saved before. - */ - Relation relation = try_relation_open(relationId, ExclusiveLock); - if (relation == NULL) + /* exclude reference tables */ + if (distributionMethod != DISTRIBUTE_BY_NONE) { - ereport(ERROR, (errmsg("could not open the relation %u", relationId), - errdetail("When creating the distribution column."))); + /* + * Because we create a new table when undistributing the table, attribute + * numbers might be changed, because of the dropped columns. To make sure we + * have the correct distribution column, we need to build it again, using the + * original column name that we have saved before. + */ + Relation relation = try_relation_open(relationId, ExclusiveLock); + if (relation == NULL) + { + ereport(ERROR, (errmsg("could not open the relation %u", relationId), + errdetail("When creating the distribution column."))); + } + + relation_close(relation, NoLock); + + distributionColumn = BuildDistributionKeyFromColumnName(relation, + distributionColumnName); } - - relation_close(relation, NoLock); - - distributionColumn = BuildDistributionKeyFromColumnName(relation, - distributionColumnName); } /*