diff --git a/src/backend/distributed/commands/comment.c b/src/backend/distributed/commands/comment.c index da8f26acb..c4d5cbdd4 100644 --- a/src/backend/distributed/commands/comment.c +++ b/src/backend/distributed/commands/comment.c @@ -18,22 +18,24 @@ #include "nodes/parsenodes.h" #include "utils/builtins.h" #include "utils/rel.h" +#include "utils/fmgroids.h" #include "distributed/comment.h" -static char * GetCommentForObject(Oid oid); +static char * GetCommentForObject(Oid classOid, Oid objectOid); List * -GetCommentPropagationCommands(Oid oid, char *objectName, ObjectType objectType) +GetCommentPropagationCommands(Oid classOid, Oid objOoid, char *objectName, ObjectType + objectType) { List *commands = NIL; StringInfo commentStmt = makeStringInfo(); /* Get the comment for the database */ - char *comment = GetCommentForObject(oid); - char const *commentObjectType = ObjectTypeInfos[objectType]; + char *comment = GetCommentForObject(classOid, objOoid); + char const *commentObjectType = ObjectTypeNames[objectType]; /* Create the SQL command to propagate the comment to other nodes */ if (comment != NULL) @@ -55,7 +57,7 @@ GetCommentPropagationCommands(Oid oid, char *objectName, ObjectType objectType) static char * -GetCommentForObject(Oid oid) +GetCommentForObject(Oid classOid, Oid objectOid) { HeapTuple tuple; char *comment = NULL; @@ -64,8 +66,21 @@ GetCommentForObject(Oid oid) Relation shdescRelation = table_open(SharedDescriptionRelationId, AccessShareLock); /* Scan the table */ - SysScanDesc scan = systable_beginscan(shdescRelation, InvalidOid, false, NULL, 0, - NULL); + ScanKeyData scanKey[2]; + + ScanKeyInit(&scanKey[0], + Anum_pg_shdescription_objoid, + BTEqualStrategyNumber, F_OIDEQ, + ObjectIdGetDatum(objectOid)); + ScanKeyInit(&scanKey[1], + Anum_pg_shdescription_classoid, + BTEqualStrategyNumber, F_OIDEQ, + ObjectIdGetDatum(classOid)); + bool indexOk = true; + int scanKeyCount = 2; + SysScanDesc scan = systable_beginscan(shdescRelation, SharedDescriptionObjIndexId, + indexOk, NULL, scanKeyCount, + scanKey); while ((tuple = systable_getnext(scan)) != NULL) { Form_pg_shdescription shdesc = (Form_pg_shdescription) GETSTRUCT(tuple); @@ -78,7 +93,7 @@ GetCommentForObject(Oid oid) &isNull); /* Check if the objoid matches the databaseOid */ - if (shdesc->objoid == oid) + if (shdesc->objoid == objectOid && shdesc->classoid == classOid) { /* Add the command to the list */ if (!isNull) diff --git a/src/backend/distributed/commands/database.c b/src/backend/distributed/commands/database.c index ab8ba6b9b..aa501fefb 100644 --- a/src/backend/distributed/commands/database.c +++ b/src/backend/distributed/commands/database.c @@ -586,7 +586,8 @@ GetDatabaseMetadataSyncCommands(Oid dbOid) List *ddlCommands = list_make1(databaseDDLCommand); List *grantDDLCommands = GrantOnDatabaseDDLCommands(dbOid); - List *commentDDLCommands = GetCommentPropagationCommands(dbOid, databaseName, + List *commentDDLCommands = GetCommentPropagationCommands(DatabaseRelationId, dbOid, + databaseName, OBJECT_DATABASE); ddlCommands = list_concat(ddlCommands, grantDDLCommands); diff --git a/src/backend/distributed/commands/role.c b/src/backend/distributed/commands/role.c index 613fa5dac..d0b33ccb9 100644 --- a/src/backend/distributed/commands/role.c +++ b/src/backend/distributed/commands/role.c @@ -591,8 +591,8 @@ GenerateCreateOrAlterRoleCommand(Oid roleOid) * for the ROLE entry corresponding to roleOid, and generate the relevant * Comment stmts to be run in the new node. */ - List *commentStmts = GetCommentPropagationCommands(roleOid, rolename, - OBJECT_ROLE); + List *commentStmts = GetCommentPropagationCommands(AuthIdRelationId, roleOid, + rolename, OBJECT_ROLE); completeRoleList = list_concat(completeRoleList, commentStmts); } diff --git a/src/backend/distributed/deparser/deparse_comment_stmts.c b/src/backend/distributed/deparser/deparse_comment_stmts.c index 2bfb15908..36a63c97b 100644 --- a/src/backend/distributed/deparser/deparse_comment_stmts.c +++ b/src/backend/distributed/deparser/deparse_comment_stmts.c @@ -29,7 +29,7 @@ #include "distributed/log_utils.h" -const char *ObjectTypeInfos[] = +const char *ObjectTypeNames[] = { [OBJECT_DATABASE] = "DATABASE", [OBJECT_ROLE] = "ROLE", @@ -66,7 +66,7 @@ DeparseCommentStmt(Node *node) errmsg("unknown object type"))); } - const char *objectType = ObjectTypeInfos[stmt->objtype]; + const char *objectType = ObjectTypeNames[stmt->objtype]; char *comment = stmt->comment != NULL ? quote_literal_cstr(stmt->comment) : "NULL"; diff --git a/src/include/distributed/comment.h b/src/include/distributed/comment.h index 7b3c0834a..bef216ae4 100644 --- a/src/include/distributed/comment.h +++ b/src/include/distributed/comment.h @@ -16,11 +16,11 @@ #include "nodes/parsenodes.h" -extern const char *ObjectTypeInfos[]; +extern const char *ObjectTypeNames[]; -extern List * GetCommentPropagationCommands(Oid oid, char *objectName, ObjectType - objectType); +extern List * GetCommentPropagationCommands(Oid classOid, Oid oid, char *objectName, + ObjectType objectType); extern List * CommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess); # endif /* COMMENT_H */