From dbc20c4f7984e8338856128afad7440d863e9ea7 Mon Sep 17 00:00:00 2001 From: gurkanindibay Date: Tue, 26 Dec 2023 18:10:55 +0300 Subject: [PATCH] Refactors object address --- src/backend/distributed/commands/comment.c | 21 ++++++++++++++++++ src/backend/distributed/commands/database.c | 22 ------------------- .../commands/distribute_object_ops.c | 9 ++++---- src/backend/distributed/commands/role.c | 22 ------------------- .../deparser/deparse_comment_stmts.c | 17 +++++++------- src/include/distributed/commands.h | 3 --- src/include/distributed/comment.h | 6 +++++ 7 files changed, 41 insertions(+), 59 deletions(-) diff --git a/src/backend/distributed/commands/comment.c b/src/backend/distributed/commands/comment.c index 893571ca3..2626163b5 100644 --- a/src/backend/distributed/commands/comment.c +++ b/src/backend/distributed/commands/comment.c @@ -123,3 +123,24 @@ GetCommentForObject(Oid oid) return comment; } + + +/* + * CommentObjectAddress resolves the ObjectAddress for the object + * on which the comment is placed. Optionally errors if the object does not + * exist based on the missing_ok flag passed in by the caller. + */ +List * +CommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess) +{ + CommentStmt *stmt = castNode(CommentStmt, node); + Relation relation; + + ObjectAddress objectAddress = get_object_address(stmt->objtype, stmt->object, + &relation, AccessExclusiveLock, + missing_ok); + + ObjectAddress *objectAddressCopy = palloc0(sizeof(ObjectAddress)); + *objectAddressCopy = objectAddress; + return list_make1(objectAddressCopy); +} diff --git a/src/backend/distributed/commands/database.c b/src/backend/distributed/commands/database.c index aea880667..ab8ba6b9b 100644 --- a/src/backend/distributed/commands/database.c +++ b/src/backend/distributed/commands/database.c @@ -793,25 +793,3 @@ CreateDatabaseDDLCommand(Oid dbId) return outerDbStmt->data; } - - -/* - * DatabaseCommentObjectAddress resolves the ObjectAddress for the DATABASE - * on which the comment is placed. Optionally errors if the database does not - * exist based on the missing_ok flag passed in by the caller. - */ -List * -DatabaseCommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess) -{ - CommentStmt *stmt = castNode(CommentStmt, node); - Relation relation; - Assert(stmt->objtype == OBJECT_DATABASE); - - ObjectAddress objectAddress = get_object_address(stmt->objtype, stmt->object, - &relation, AccessExclusiveLock, - missing_ok); - - ObjectAddress *objectAddressCopy = palloc0(sizeof(ObjectAddress)); - *objectAddressCopy = objectAddress; - return list_make1(objectAddressCopy); -} diff --git a/src/backend/distributed/commands/distribute_object_ops.c b/src/backend/distributed/commands/distribute_object_ops.c index 6e39f9d38..b7b603749 100644 --- a/src/backend/distributed/commands/distribute_object_ops.c +++ b/src/backend/distributed/commands/distribute_object_ops.c @@ -15,6 +15,7 @@ #include "pg_version_constants.h" #include "distributed/commands.h" +#include "distributed/comment.h" #include "distributed/commands/utility_hook.h" #include "distributed/deparser.h" #include "distributed/version_compat.h" @@ -312,7 +313,7 @@ static DistributeObjectOps Role_Comment = { .postprocess = NULL, .objectType = OBJECT_DATABASE, .operationType = DIST_OPS_ALTER, - .address = RoleCommentObjectAddress, + .address = CommentObjectAddress, .markDistributed = false, }; static DistributeObjectOps Any_CreateForeignServer = { @@ -551,7 +552,7 @@ static DistributeObjectOps Database_Comment = { .postprocess = NULL, .objectType = OBJECT_DATABASE, .operationType = DIST_OPS_ALTER, - .address = DatabaseCommentObjectAddress, + .address = CommentObjectAddress, .markDistributed = false, }; @@ -1000,7 +1001,7 @@ static DistributeObjectOps TextSearchConfig_Comment = { .postprocess = NULL, .objectType = OBJECT_TSCONFIGURATION, .operationType = DIST_OPS_ALTER, - .address = TextSearchConfigurationCommentObjectAddress, + .address = CommentObjectAddress, .markDistributed = false, }; static DistributeObjectOps TextSearchConfig_Define = { @@ -1069,7 +1070,7 @@ static DistributeObjectOps TextSearchDict_Comment = { .postprocess = NULL, .objectType = OBJECT_TSDICTIONARY, .operationType = DIST_OPS_ALTER, - .address = TextSearchDictCommentObjectAddress, + .address = CommentObjectAddress, .markDistributed = false, }; static DistributeObjectOps TextSearchDict_Define = { diff --git a/src/backend/distributed/commands/role.c b/src/backend/distributed/commands/role.c index 614a93000..613fa5dac 100644 --- a/src/backend/distributed/commands/role.c +++ b/src/backend/distributed/commands/role.c @@ -1424,25 +1424,3 @@ RenameRoleStmtObjectAddress(Node *node, bool missing_ok, bool isPostprocess) return list_make1(address); } - - -/* - * RoleCommentObjectAddress resolves the ObjectAddress for the ROLE - * on which the comment is placed. Optionally errors if the role does not - * exist based on the missing_ok flag passed in by the caller. - */ -List * -RoleCommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess) -{ - CommentStmt *stmt = castNode(CommentStmt, node); - Relation relation; - Assert(stmt->objtype == OBJECT_ROLE); - - ObjectAddress objectAddress = get_object_address(stmt->objtype, stmt->object, - &relation, AccessExclusiveLock, - missing_ok); - - ObjectAddress *objectAddressCopy = palloc0(sizeof(ObjectAddress)); - *objectAddressCopy = objectAddress; - return list_make1(objectAddressCopy); -} diff --git a/src/backend/distributed/deparser/deparse_comment_stmts.c b/src/backend/distributed/deparser/deparse_comment_stmts.c index 25be9eac8..4aee4008e 100644 --- a/src/backend/distributed/deparser/deparse_comment_stmts.c +++ b/src/backend/distributed/deparser/deparse_comment_stmts.c @@ -27,13 +27,14 @@ #include "distributed/log_utils.h" -const char * const ObjectTypeNames[] = +const char *const ObjectTypeNames[] = { - [OBJECT_DATABASE] = "DATABASE", - [OBJECT_ROLE] = "ROLE", - [OBJECT_TSCONFIGURATION] = "TEXT SEARCH CONFIGURATION", - [OBJECT_TSDICTIONARY] = "TEXT SEARCH DICTIONARY", - /* etc. */ + [OBJECT_DATABASE] = "DATABASE", + [OBJECT_ROLE] = "ROLE", + [OBJECT_TSCONFIGURATION] = "TEXT SEARCH CONFIGURATION", + [OBJECT_TSDICTIONARY] = "TEXT SEARCH DICTIONARY", + + /* etc. */ }; char * @@ -44,12 +45,12 @@ DeparseCommentStmt(Node *node) initStringInfo(&str); const char *objectName = quote_identifier(strVal(stmt->object)); - const char *objectType = ObjectTypeNames[stmt->objtype]; + const char *objectType = ObjectTypeNames[stmt->objtype]; char *comment = stmt->comment != NULL ? quote_literal_cstr(stmt->comment) : "NULL"; - appendStringInfo(&str, "COMMENT ON %s %s IS %s;",objectType, objectName, comment); + appendStringInfo(&str, "COMMENT ON %s %s IS %s;", objectType, objectName, comment); return str.data; } diff --git a/src/include/distributed/commands.h b/src/include/distributed/commands.h index f155383c5..7c9b3f095 100644 --- a/src/include/distributed/commands.h +++ b/src/include/distributed/commands.h @@ -249,8 +249,6 @@ extern List * GenerateGrantDatabaseCommandList(void); extern List * PostprocessAlterDatabaseRenameStmt(Node *node, const char *queryString); extern void EnsureSupportedCreateDatabaseCommand(CreatedbStmt *stmt); extern char * CreateDatabaseDDLCommand(Oid dbId); -extern List * DatabaseCommentObjectAddress(Node *node, bool missing_ok, - bool isPostprocess); /* domain.c - forward declarations */ @@ -523,7 +521,6 @@ extern List * RenameRoleStmtObjectAddress(Node *stmt, bool missing_ok, bool extern void UnmarkRolesDistributed(List *roles); extern List * FilterDistributedRoles(List *roles); -List * RoleCommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess); /* schema.c - forward declarations */ extern List * PostprocessCreateSchemaStmt(Node *node, const char *queryString); diff --git a/src/include/distributed/comment.h b/src/include/distributed/comment.h index b25a865f6..5a52fa352 100644 --- a/src/include/distributed/comment.h +++ b/src/include/distributed/comment.h @@ -8,6 +8,9 @@ *------------------------------------------------------------------------- */ +#ifndef COMMENT_H +#define COMMENT_H + #include "postgres.h" #include "nodes/parsenodes.h" @@ -21,3 +24,6 @@ typedef struct CommentStmtType extern List * GetCommentPropagationCommands(Oid oid, char *objectName, ObjectType objectType); +extern List * CommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess); + +# endif /* COMMENT_H */