diff --git a/src/backend/distributed/commands/alter_table.c b/src/backend/distributed/commands/alter_table.c index c24e9bb91..f58322ea4 100644 --- a/src/backend/distributed/commands/alter_table.c +++ b/src/backend/distributed/commands/alter_table.c @@ -573,8 +573,9 @@ ConvertTable(TableConversionState *con) List *justBeforeDropCommands = NIL; List *attachPartitionCommands = NIL; - postLoadCommands = list_concat(postLoadCommands, - GetViewCreationCommandsOfTable(con->relationId, true)); + postLoadCommands = + list_concat(postLoadCommands, + GetViewCreationTableDDLCommandsOfTable(con->relationId)); List *foreignKeyCommands = NIL; if (con->conversionType == ALTER_DISTRIBUTED_TABLE) @@ -1255,7 +1256,7 @@ CreateCitusTableLike(TableConversionState *con) * that recursively depend on the table too. */ List * -GetViewCreationCommandsOfTable(Oid relationId, bool asTableDDLCommand) +GetViewCreationCommandsOfTable(Oid relationId) { List *views = GetDependingViews(relationId); List *commands = NIL; @@ -1280,20 +1281,33 @@ GetViewCreationCommandsOfTable(Oid relationId, bool asTableDDLCommand) char *alterViewCommmand = AlterViewOwnerCommand(viewOid); appendStringInfoString(query, alterViewCommmand); - if (asTableDDLCommand) - { - commands = lappend(commands, makeTableDDLCommandString(query->data)); - } - else - { - commands = lappend(commands, query->data); - } + commands = lappend(commands, query->data); } return commands; } +/* + * GetViewCreationTableDDLCommandsOfTable is the same as GetViewCreationCommandsOfTable, + * but the returned list includes objects of TableDDLCommand's, not strings. + */ +List * +GetViewCreationTableDDLCommandsOfTable(Oid relationId) +{ + List *commands = GetViewCreationCommandsOfTable(relationId); + List *tableDDLCommands = NIL; + + char *command = NULL; + foreach_ptr(command, commands) + { + tableDDLCommands = lappend(tableDDLCommands, makeTableDDLCommandString(command)); + } + + return tableDDLCommands; +} + + /* * CreateMaterializedViewDDLCommand creates the command to create materialized view. * Note that this function doesn't support diff --git a/src/backend/distributed/commands/citus_add_local_table_to_metadata.c b/src/backend/distributed/commands/citus_add_local_table_to_metadata.c index b76d210d3..7645d9eab 100644 --- a/src/backend/distributed/commands/citus_add_local_table_to_metadata.c +++ b/src/backend/distributed/commands/citus_add_local_table_to_metadata.c @@ -329,7 +329,7 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys, bool autoConve EnsureReferenceTablesExistOnAllNodes(); List *shellTableDDLEvents = GetShellTableDDLEventsForCitusLocalTable(relationId); - List *tableViewCreationCommands = GetViewCreationCommandsOfTable(relationId, false); + List *tableViewCreationCommands = GetViewCreationCommandsOfTable(relationId); char *relationName = get_rel_name(relationId); Oid relationSchemaId = get_rel_namespace(relationId); diff --git a/src/include/distributed/commands.h b/src/include/distributed/commands.h index 17abc3d77..5e48d238e 100644 --- a/src/include/distributed/commands.h +++ b/src/include/distributed/commands.h @@ -534,7 +534,8 @@ extern ObjectAddress AlterViewStmtObjectAddress(Node *node, bool missing_ok); extern List * PreprocessDropViewStmt(Node *node, const char *queryString, ProcessUtilityContext processUtilityContext); extern char * CreateViewDDLCommand(Oid viewOid); -extern List * GetViewCreationCommandsOfTable(Oid relationId, bool asTableDDLCommand); +extern List * GetViewCreationCommandsOfTable(Oid relationId); +extern List * GetViewCreationTableDDLCommandsOfTable(Oid relationId); extern char * AlterViewOwnerCommand(Oid viewOid); extern char * DeparseViewStmt(Node *node); extern char * DeparseDropViewStmt(Node *node); diff --git a/src/test/regress/expected/view_propagation.out b/src/test/regress/expected/view_propagation.out index 6b49120cc..fbea07ad3 100644 --- a/src/test/regress/expected/view_propagation.out +++ b/src/test/regress/expected/view_propagation.out @@ -574,6 +574,7 @@ BEGIN; --------------------------------------------------------------------- (1 row) + CREATE TABLE table_2_to_view_in_transaction(a int); SELECT create_distributed_table('table_2_to_view_in_transaction', 'a'); create_distributed_table