From 9fa72545e247bc40afbbbdc752f1b8a327199ac5 Mon Sep 17 00:00:00 2001 From: Naisila Puka <37271756+naisila@users.noreply.github.com> Date: Thu, 17 Aug 2023 11:22:34 +0300 Subject: [PATCH] PG16 compatibility - fix AM dependency and grant's admin option (#7113) PG16 compatibility - part 11 Check out part 1 https://github.com/citusdata/citus/commit/42d956888d5be65153ccf24cb039027ecd7c0192 part 2 https://github.com/citusdata/citus/commit/0d503dd5ac5547ca71cd0147e53236d8d8a22fce part 3 https://github.com/citusdata/citus/commit/907d72e60d4043924f52200b24d281fe7b79f75f part 4 https://github.com/citusdata/citus/commit/7c6b4ce1035491ff5a31a9d15bb8b28f3c0dd5b3 part 5 https://github.com/citusdata/citus/commit/6056cb2c2931ae33b42f009872385af518cf2f8b part 6 https://github.com/citusdata/citus/commit/b36c431abbe3f70ba18de5610570adfa9d72d56d part 7 https://github.com/citusdata/citus/commit/ee3153fe5062821e8b83fb7bf62a67a20bbb5098 part 8 https://github.com/citusdata/citus/commit/2c50b5f7ff5e0c08c92a93b2b3292c403826a32a part 9 https://github.com/citusdata/citus/commit/b2291374b4e894b00c1b166ac424072ff8c29bee part 10 https://github.com/citusdata/citus/commit/a2315fdc677675b420913ca4f81116e165d52397 This commit is in the series of PG16 compatibility commits. It fixes AM dependency and grant's admin option: - Fix with admin option in grants grantstmt->admin_opt no longer exists in PG16 instead, grantstmt has a list of options, one of them is admin option. Relevant PG commit: https://github.com/postgres/postgres/commit/e3ce2de09d814f8770b2e3b3c152b7671bcdb83f e3ce2de09d814f8770b2e3b3c152b7671bcdb83f - Fix pg_depend entry to AMs after ALTER TABLE .. SET ACCESS METHOD Relevant PG commit: https://github.com/postgres/postgres/commit/97d89101045fac8cb36f4ef6c08526ea0841a596 97d89101045fac8cb36f4ef6c08526ea0841a596 More PG16 compatibility commits are coming soon: We are very close to merging "PG16Beta3 Support - Regression tests sanity" --- src/backend/distributed/commands/role.c | 15 ++++++++-- .../distributed/deparser/deparse_role_stmts.c | 28 +++++++++++++++++-- src/backend/distributed/metadata/dependency.c | 7 +++-- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/backend/distributed/commands/role.c b/src/backend/distributed/commands/role.c index 4e274d270..99ce4fb9f 100644 --- a/src/backend/distributed/commands/role.c +++ b/src/backend/distributed/commands/role.c @@ -819,12 +819,15 @@ GenerateGrantRoleStmtsFromOptions(RoleSpec *roleSpec, List *options) grantRoleStmt->grantee_roles = list_make1(roleSpec); } -#if PG_VERSION_NUM < PG_VERSION_16 if (strcmp(option->defname, "adminmembers") == 0) { +#if PG_VERSION_NUM >= PG_VERSION_16 + DefElem *opt = makeDefElem("admin", (Node *) makeBoolean(true), -1); + grantRoleStmt->opt = list_make1(opt); +#else grantRoleStmt->admin_opt = true; - } #endif + } stmts = lappend(stmts, grantRoleStmt); } @@ -871,7 +874,13 @@ GenerateGrantRoleStmtsOfRole(Oid roleid) grantRoleStmt->grantor = NULL; -#if PG_VERSION_NUM < PG_VERSION_16 +#if PG_VERSION_NUM >= PG_VERSION_16 + if (membership->admin_option) + { + DefElem *opt = makeDefElem("admin", (Node *) makeBoolean(true), -1); + grantRoleStmt->opt = list_make1(opt); + } +#else grantRoleStmt->admin_opt = membership->admin_option; #endif diff --git a/src/backend/distributed/deparser/deparse_role_stmts.c b/src/backend/distributed/deparser/deparse_role_stmts.c index 620e7606d..4ad4f4c7f 100644 --- a/src/backend/distributed/deparser/deparse_role_stmts.c +++ b/src/backend/distributed/deparser/deparse_role_stmts.c @@ -17,6 +17,7 @@ #include "distributed/citus_ruleutils.h" #include "distributed/deparser.h" +#include "distributed/listutils.h" #include "lib/stringinfo.h" #include "nodes/parsenodes.h" #include "utils/builtins.h" @@ -349,7 +350,20 @@ AppendGrantRoleStmt(StringInfo buf, GrantRoleStmt *stmt) { appendStringInfo(buf, "%s ", stmt->is_grant ? "GRANT" : "REVOKE"); -#if PG_VERSION_NUM < PG_VERSION_16 +#if PG_VERSION_NUM >= PG_VERSION_16 + if (!stmt->is_grant) + { + DefElem *opt = NULL; + foreach_ptr(opt, stmt->opt) + { + if (strcmp(opt->defname, "admin") == 0) + { + appendStringInfo(buf, "ADMIN OPTION FOR "); + break; + } + } + } +#else if (!stmt->is_grant && stmt->admin_opt) { appendStringInfo(buf, "ADMIN OPTION FOR "); @@ -364,7 +378,17 @@ AppendGrantRoleStmt(StringInfo buf, GrantRoleStmt *stmt) if (stmt->is_grant) { -#if PG_VERSION_NUM < PG_VERSION_16 +#if PG_VERSION_NUM >= PG_VERSION_16 + DefElem *opt = NULL; + foreach_ptr(opt, stmt->opt) + { + if (strcmp(opt->defname, "admin") == 0) + { + appendStringInfo(buf, " WITH ADMIN OPTION"); + break; + } + } +#else if (stmt->admin_opt) { appendStringInfo(buf, " WITH ADMIN OPTION"); diff --git a/src/backend/distributed/metadata/dependency.c b/src/backend/distributed/metadata/dependency.c index 895f97729..f970cecd1 100644 --- a/src/backend/distributed/metadata/dependency.c +++ b/src/backend/distributed/metadata/dependency.c @@ -1022,11 +1022,12 @@ GetUndistributableDependency(const ObjectAddress *objectAddress) if (!SupportedDependencyByCitus(dependency)) { /* - * Since we do not yet support distributed TS TEMPLATE objects, we skip + * Since we do not yet support distributed TS TEMPLATE and AM objects, we skip * dependency checks for text search templates. The user is expected to - * manually create the TS TEMPLATE objects. + * manually create the TS TEMPLATE and AM objects. */ - if (getObjectClass(dependency) != OCLASS_TSTEMPLATE) + if (getObjectClass(dependency) != OCLASS_TSTEMPLATE && + getObjectClass(dependency) != OCLASS_AM) { return dependency; }