From 1f8de3484ebcecc7f69b3e528bcdaffd7217aed9 Mon Sep 17 00:00:00 2001 From: Ahmet Gedemenli Date: Fri, 20 May 2022 19:07:27 +0300 Subject: [PATCH] Use CreateViewDDLCommand in GetViewCreationCommandsOfTable --- .../distributed/commands/alter_table.c | 58 +------------------ 1 file changed, 2 insertions(+), 56 deletions(-) diff --git a/src/backend/distributed/commands/alter_table.c b/src/backend/distributed/commands/alter_table.c index fe3f7d0a3..e2425983a 100644 --- a/src/backend/distributed/commands/alter_table.c +++ b/src/backend/distributed/commands/alter_table.c @@ -206,7 +206,6 @@ static char * CreateWorkerChangeSequenceDependencyCommand(char *sequenceSchemaNa char *sourceName, char *targetSchemaName, char *targetName); -static char * GetAccessMethodForMatViewIfExists(Oid viewOid); static bool WillRecreateForeignKeyToReferenceTable(Oid relationId, CascadeToColocatedOption cascadeOption); static void WarningsForDroppingForeignKeysWithDistributedTables(Oid relationId); @@ -1263,35 +1262,8 @@ GetViewCreationCommandsOfTable(Oid relationId) Oid viewOid = InvalidOid; foreach_oid(viewOid, views) { - Datum viewDefinitionDatum = DirectFunctionCall1(pg_get_viewdef, - ObjectIdGetDatum(viewOid)); - char *viewDefinition = TextDatumGetCString(viewDefinitionDatum); - StringInfo query = makeStringInfo(); - char *viewName = get_rel_name(viewOid); - char *schemaName = get_namespace_name(get_rel_namespace(viewOid)); - char *qualifiedViewName = quote_qualified_identifier(schemaName, viewName); - bool isMatView = get_rel_relkind(viewOid) == RELKIND_MATVIEW; - - /* here we need to get the access method of the view to recreate it */ - char *accessMethodName = GetAccessMethodForMatViewIfExists(viewOid); - - appendStringInfoString(query, "CREATE "); - - if (isMatView) - { - appendStringInfoString(query, "MATERIALIZED "); - } - - appendStringInfo(query, "VIEW %s ", qualifiedViewName); - - if (accessMethodName) - { - appendStringInfo(query, "USING %s ", accessMethodName); - } - - appendStringInfo(query, "AS %s", viewDefinition); - - commands = lappend(commands, makeTableDDLCommandString(query->data)); + char *createViewCommand = CreateViewDDLCommand(viewOid); + commands = lappend(commands, makeTableDDLCommandString(createViewCommand)); } return commands; @@ -1694,32 +1666,6 @@ CreateWorkerChangeSequenceDependencyCommand(char *sequenceSchemaName, char *sequ } -/* - * GetAccessMethodForMatViewIfExists returns if there's an access method - * set to the view with the given oid. Returns NULL otherwise. - */ -static char * -GetAccessMethodForMatViewIfExists(Oid viewOid) -{ - char *accessMethodName = NULL; - Relation relation = try_relation_open(viewOid, AccessShareLock); - if (relation == NULL) - { - ereport(ERROR, (errmsg("cannot complete operation " - "because no such view exists"))); - } - - Oid accessMethodOid = relation->rd_rel->relam; - if (OidIsValid(accessMethodOid)) - { - accessMethodName = get_am_name(accessMethodOid); - } - relation_close(relation, NoLock); - - return accessMethodName; -} - - /* * WillRecreateForeignKeyToReferenceTable checks if the table of relationId has any foreign * key to a reference table, if conversion will be cascaded to colocated table this function