From f21a80bbef924f2a70dcbded2cd94a0f6d139f1d Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Wed, 13 Apr 2022 16:31:29 +0300 Subject: [PATCH] Self-review --- src/backend/distributed/commands/view.c | 12 ++++------ ...parse_view_stmt.c => deparse_view_stmts.c} | 23 ++++++------------- src/include/distributed/deparser.h | 1 + 3 files changed, 12 insertions(+), 24 deletions(-) rename src/backend/distributed/deparser/{deparse_view_stmt.c => deparse_view_stmts.c} (91%) diff --git a/src/backend/distributed/commands/view.c b/src/backend/distributed/commands/view.c index 6ff3f632e..31bc66c42 100644 --- a/src/backend/distributed/commands/view.c +++ b/src/backend/distributed/commands/view.c @@ -42,9 +42,6 @@ static void AppendAliasesToCreateViewCommandForExistingView(StringInfo createVie /* * PreprocessViewStmt is called during the planning phase for CREATE OR REPLACE VIEW * before it is created on the local node internally. - * - * We do our basic housekeeping where we make sure we are on the coordinator and - * qualify the given statement. */ List * PreprocessViewStmt(Node *node, const char *queryString, @@ -256,12 +253,8 @@ CreateViewDDLCommandsIdempotent(const ObjectAddress *viewAddress) char *schemaName = get_namespace_name(schemaOid); appendStringInfoString(createViewCommand, "CREATE OR REPLACE VIEW "); - char *qualifiedViewName = NameListToQuotedString(list_make2(makeString(schemaName), - makeString(viewName))); - appendStringInfo(createViewCommand, "%s ", qualifiedViewName); - - /* Add column aliases to create view command */ + AddQualifiedViewNameToCreateViewCommand(createViewCommand, viewOid); AppendAliasesToCreateViewCommandForExistingView(createViewCommand, viewOid); /* Add rel options to create view command */ @@ -277,7 +270,10 @@ CreateViewDDLCommandsIdempotent(const ObjectAddress *viewAddress) /* Add alter owner commmand */ StringInfo alterOwnerCommand = makeStringInfo(); + char *viewOwnerName = TableOwner(viewOid); + char *qualifiedViewName = NameListToQuotedString(list_make2(makeString(schemaName), + makeString(viewName))); appendStringInfo(alterOwnerCommand, "ALTER VIEW %s OWNER TO %s", qualifiedViewName, quote_identifier(viewOwnerName)); diff --git a/src/backend/distributed/deparser/deparse_view_stmt.c b/src/backend/distributed/deparser/deparse_view_stmts.c similarity index 91% rename from src/backend/distributed/deparser/deparse_view_stmt.c rename to src/backend/distributed/deparser/deparse_view_stmts.c index dc240c093..673b71194 100644 --- a/src/backend/distributed/deparser/deparse_view_stmt.c +++ b/src/backend/distributed/deparser/deparse_view_stmts.c @@ -22,7 +22,6 @@ #include "utils/builtins.h" #include "utils/lsyscache.h" -static void AddQualifiedViewNameToCreateViewCommand(StringInfo buf, Oid viewOid); static void AddAliasesToCreateViewCommand(StringInfo buf, ViewStmt *stmt); static void AddOptionsToCreateViewCommand(StringInfo buf, ViewStmt *stmt); static void AppendDropViewStmt(StringInfo buf, DropStmt *stmt); @@ -42,20 +41,13 @@ DeparseViewStmt(Node *node) if (stmt->replace) { - appendStringInfoString(viewString, "CREATE OR REPLACE "); + appendStringInfoString(viewString, "CREATE OR REPLACE VIEW "); } else { - appendStringInfoString(viewString, "CREATE "); + appendStringInfoString(viewString, "CREATE VIEW "); } - if (stmt->view->relpersistence == RELPERSISTENCE_TEMP) - { - appendStringInfoString(viewString, "TEMPORARY "); - } - - appendStringInfo(viewString, "VIEW "); - AddQualifiedViewNameToCreateViewCommand(viewString, viewOid); AddAliasesToCreateViewCommand(viewString, stmt); AddOptionsToCreateViewCommand(viewString, stmt); @@ -74,9 +66,9 @@ DeparseViewStmt(Node *node) /* * AddQualifiedViewNameToCreateViewCommand adds the qualified view of the given view - * statement to the given create view command. + * oid to the given create view command. */ -static void +void AddQualifiedViewNameToCreateViewCommand(StringInfo buf, Oid viewOid) { char *viewName = get_rel_name(viewOid); @@ -125,7 +117,7 @@ AddAliasesToCreateViewCommand(StringInfo buf, ViewStmt *stmt) /* * AddOptionsToCreateViewCommand appends options (if exists) of the given view statement * to the given create view command. Note that this function also handles - * WITH [CASCADED | LOCAL] CHECK OPTION part of the CREATE VIEW command as well. + * WITH [CASCADED | LOCAL] CHECK OPTION part of the CREATE VIEW command. */ static void AddOptionsToCreateViewCommand(StringInfo buf, ViewStmt *stmt) @@ -152,7 +144,7 @@ AddOptionsToCreateViewCommand(StringInfo buf, ViewStmt *stmt) } appendStringInfoString(buf, option->defname); - appendStringInfoString(buf, " = "); + appendStringInfoString(buf, "="); appendStringInfoString(buf, defGetString(option)); } @@ -169,8 +161,7 @@ AddViewDefinitionToCreateViewCommand(StringInfo buf, Oid viewOid) { /* * Set search_path to NIL so that all objects outside of pg_catalog will be - * schema-prefixed. pg_catalog will be added automatically when we call - * PushOverrideSearchPath(), since we set addCatalog to true; + * schema-prefixed. */ OverrideSearchPath *overridePath = GetOverrideSearchPath(CurrentMemoryContext); overridePath->schemas = NIL; diff --git a/src/include/distributed/deparser.h b/src/include/distributed/deparser.h index d35ddaf91..d992b1214 100644 --- a/src/include/distributed/deparser.h +++ b/src/include/distributed/deparser.h @@ -147,6 +147,7 @@ extern ObjectAddress RenameAttributeStmtObjectAddress(Node *stmt, bool missing_o /* forward declarations for deparse_view_stmts.c */ extern void QualifyDropViewStmt(Node *node); extern void AddViewDefinitionToCreateViewCommand(StringInfo buf, Oid viewOid); +extern void AddQualifiedViewNameToCreateViewCommand(StringInfo buf, Oid viewOid); /* forward declarations for deparse_function_stmts.c */ extern char * DeparseDropFunctionStmt(Node *stmt);