From 147a110917a19d880d279764546a6cdcfa48db61 Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Thu, 16 Jun 2022 15:46:52 +0300 Subject: [PATCH] Do not drop and recreate materialized views while creating local table --- src/backend/distributed/commands/alter_table.c | 13 +++++++++---- .../commands/citus_add_local_table_to_metadata.c | 14 +++++++++++--- src/include/distributed/commands.h | 5 +++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/backend/distributed/commands/alter_table.c b/src/backend/distributed/commands/alter_table.c index d6791c9ee..3930ab8da 100644 --- a/src/backend/distributed/commands/alter_table.c +++ b/src/backend/distributed/commands/alter_table.c @@ -585,7 +585,7 @@ ConvertTable(TableConversionState *con) postLoadCommands = list_concat(postLoadCommands, - GetViewCreationTableDDLCommandsOfTable(con->relationId)); + GetViewCreationTableDDLCommandsOfTable(con->relationId, true)); List *foreignKeyCommands = NIL; if (con->conversionType == ALTER_DISTRIBUTED_TABLE) @@ -1354,7 +1354,7 @@ DoesCascadeDropUnsupportedObject(Oid classId, Oid objectId, HTAB *nodeMap) * that recursively depend on the table too. */ List * -GetViewCreationCommandsOfTable(Oid relationId) +GetViewCreationCommandsOfTable(Oid relationId, bool includeMatViews) { List *views = GetDependingViews(relationId); List *commands = NIL; @@ -1367,6 +1367,11 @@ GetViewCreationCommandsOfTable(Oid relationId) /* See comments on CreateMaterializedViewDDLCommand for its limitations */ if (get_rel_relkind(viewOid) == RELKIND_MATVIEW) { + if (!includeMatViews) + { + continue; + } + char *matViewCreateCommands = CreateMaterializedViewDDLCommand(viewOid); appendStringInfoString(query, matViewCreateCommands); } @@ -1391,9 +1396,9 @@ GetViewCreationCommandsOfTable(Oid relationId) * but the returned list includes objects of TableDDLCommand's, not strings. */ List * -GetViewCreationTableDDLCommandsOfTable(Oid relationId) +GetViewCreationTableDDLCommandsOfTable(Oid relationId, bool includeMatViews) { - List *commands = GetViewCreationCommandsOfTable(relationId); + List *commands = GetViewCreationCommandsOfTable(relationId, includeMatViews); List *tableDDLCommands = NIL; char *command = NULL; 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 d9335fcbc..74c3caa44 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 @@ -330,7 +330,7 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys, bool autoConve EnsureReferenceTablesExistOnAllNodes(); List *shellTableDDLEvents = GetShellTableDDLEventsForCitusLocalTable(relationId); - List *tableViewCreationCommands = GetViewCreationCommandsOfTable(relationId); + List *tableViewCreationCommands = GetViewCreationCommandsOfTable(relationId, false); char *relationName = get_rel_name(relationId); Oid relationSchemaId = get_rel_namespace(relationId); @@ -1053,8 +1053,16 @@ DropViewsOnTable(Oid relationId) char *qualifiedViewName = quote_qualified_identifier(schemaName, viewName); StringInfo dropCommand = makeStringInfo(); - appendStringInfo(dropCommand, "DROP VIEW IF EXISTS %s", - qualifiedViewName); + if (get_rel_relkind(viewId) == RELKIND_MATVIEW) + { + /* + * Since materialized views are not supported with Citus right now, + * skip them + */ + continue; + } + + appendStringInfo(dropCommand, "DROP VIEW IF EXISTS %s", qualifiedViewName); ExecuteAndLogUtilityCommand(dropCommand->data); } diff --git a/src/include/distributed/commands.h b/src/include/distributed/commands.h index 1db02fd3c..9dbf5209f 100644 --- a/src/include/distributed/commands.h +++ b/src/include/distributed/commands.h @@ -564,8 +564,9 @@ 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); -extern List * GetViewCreationTableDDLCommandsOfTable(Oid relationId); +extern List * GetViewCreationCommandsOfTable(Oid relationId, bool includeMatViews); +extern List * GetViewCreationTableDDLCommandsOfTable(Oid relationId, bool + includeMatViews); extern char * AlterViewOwnerCommand(Oid viewOid); extern char * DeparseViewStmt(Node *node); extern char * DeparseDropViewStmt(Node *node);