Fixes review issues

pull/7388/head
gurkanindibay 2024-01-10 17:17:41 +03:00
parent b4dc579280
commit ecd487914f
5 changed files with 32 additions and 16 deletions

View File

@ -18,22 +18,24 @@
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/rel.h" #include "utils/rel.h"
#include "utils/fmgroids.h"
#include "distributed/comment.h" #include "distributed/comment.h"
static char * GetCommentForObject(Oid oid); static char * GetCommentForObject(Oid classOid, Oid objectOid);
List * List *
GetCommentPropagationCommands(Oid oid, char *objectName, ObjectType objectType) GetCommentPropagationCommands(Oid classOid, Oid objOoid, char *objectName, ObjectType
objectType)
{ {
List *commands = NIL; List *commands = NIL;
StringInfo commentStmt = makeStringInfo(); StringInfo commentStmt = makeStringInfo();
/* Get the comment for the database */ /* Get the comment for the database */
char *comment = GetCommentForObject(oid); char *comment = GetCommentForObject(classOid, objOoid);
char const *commentObjectType = ObjectTypeInfos[objectType]; char const *commentObjectType = ObjectTypeNames[objectType];
/* Create the SQL command to propagate the comment to other nodes */ /* Create the SQL command to propagate the comment to other nodes */
if (comment != NULL) if (comment != NULL)
@ -55,7 +57,7 @@ GetCommentPropagationCommands(Oid oid, char *objectName, ObjectType objectType)
static char * static char *
GetCommentForObject(Oid oid) GetCommentForObject(Oid classOid, Oid objectOid)
{ {
HeapTuple tuple; HeapTuple tuple;
char *comment = NULL; char *comment = NULL;
@ -64,8 +66,21 @@ GetCommentForObject(Oid oid)
Relation shdescRelation = table_open(SharedDescriptionRelationId, AccessShareLock); Relation shdescRelation = table_open(SharedDescriptionRelationId, AccessShareLock);
/* Scan the table */ /* Scan the table */
SysScanDesc scan = systable_beginscan(shdescRelation, InvalidOid, false, NULL, 0, ScanKeyData scanKey[2];
NULL);
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) while ((tuple = systable_getnext(scan)) != NULL)
{ {
Form_pg_shdescription shdesc = (Form_pg_shdescription) GETSTRUCT(tuple); Form_pg_shdescription shdesc = (Form_pg_shdescription) GETSTRUCT(tuple);
@ -78,7 +93,7 @@ GetCommentForObject(Oid oid)
&isNull); &isNull);
/* Check if the objoid matches the databaseOid */ /* Check if the objoid matches the databaseOid */
if (shdesc->objoid == oid) if (shdesc->objoid == objectOid && shdesc->classoid == classOid)
{ {
/* Add the command to the list */ /* Add the command to the list */
if (!isNull) if (!isNull)

View File

@ -586,7 +586,8 @@ GetDatabaseMetadataSyncCommands(Oid dbOid)
List *ddlCommands = list_make1(databaseDDLCommand); List *ddlCommands = list_make1(databaseDDLCommand);
List *grantDDLCommands = GrantOnDatabaseDDLCommands(dbOid); List *grantDDLCommands = GrantOnDatabaseDDLCommands(dbOid);
List *commentDDLCommands = GetCommentPropagationCommands(dbOid, databaseName, List *commentDDLCommands = GetCommentPropagationCommands(DatabaseRelationId, dbOid,
databaseName,
OBJECT_DATABASE); OBJECT_DATABASE);
ddlCommands = list_concat(ddlCommands, grantDDLCommands); ddlCommands = list_concat(ddlCommands, grantDDLCommands);

View File

@ -591,8 +591,8 @@ GenerateCreateOrAlterRoleCommand(Oid roleOid)
* for the ROLE entry corresponding to roleOid, and generate the relevant * for the ROLE entry corresponding to roleOid, and generate the relevant
* Comment stmts to be run in the new node. * Comment stmts to be run in the new node.
*/ */
List *commentStmts = GetCommentPropagationCommands(roleOid, rolename, List *commentStmts = GetCommentPropagationCommands(AuthIdRelationId, roleOid,
OBJECT_ROLE); rolename, OBJECT_ROLE);
completeRoleList = list_concat(completeRoleList, commentStmts); completeRoleList = list_concat(completeRoleList, commentStmts);
} }

View File

@ -29,7 +29,7 @@
#include "distributed/log_utils.h" #include "distributed/log_utils.h"
const char *ObjectTypeInfos[] = const char *ObjectTypeNames[] =
{ {
[OBJECT_DATABASE] = "DATABASE", [OBJECT_DATABASE] = "DATABASE",
[OBJECT_ROLE] = "ROLE", [OBJECT_ROLE] = "ROLE",
@ -66,7 +66,7 @@ DeparseCommentStmt(Node *node)
errmsg("unknown object type"))); 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"; char *comment = stmt->comment != NULL ? quote_literal_cstr(stmt->comment) : "NULL";

View File

@ -16,11 +16,11 @@
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
extern const char *ObjectTypeInfos[]; extern const char *ObjectTypeNames[];
extern List * GetCommentPropagationCommands(Oid oid, char *objectName, ObjectType extern List * GetCommentPropagationCommands(Oid classOid, Oid oid, char *objectName,
objectType); ObjectType objectType);
extern List * CommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess); extern List * CommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess);
# endif /* COMMENT_H */ # endif /* COMMENT_H */