Create GetViewCreationTableDDLCommandsOfTable

velioglu/prop_dep_view_review
Ahmet Gedemenli 2022-05-24 18:09:38 +03:00
parent 1b39051aef
commit 73a600c203
4 changed files with 29 additions and 13 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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