From bb82b2bae5f706ba28046bd4d9c1400a1d02d636 Mon Sep 17 00:00:00 2001 From: Rishabh Tanwar <33982749+rishabhtanwar29@users.noreply.github.com> Date: Wed, 20 Nov 2024 20:25:44 +0530 Subject: [PATCH 1/5] Enable babelfishpg_tsql.dump_restore GUC while restoring roles (#467) (#478) Set babelfishpg_tsql.dump_restore GUC to true while restoring roles so that we can use this to add special handling during restore. Task: BABEL-5039 Signed-off-by: Rishabh Tanwar ritanwar@amazon.com --- src/bin/pg_dump/dumpall_babel_utils.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bin/pg_dump/dumpall_babel_utils.c b/src/bin/pg_dump/dumpall_babel_utils.c index baae7175821..a185690d9ef 100644 --- a/src/bin/pg_dump/dumpall_babel_utils.c +++ b/src/bin/pg_dump/dumpall_babel_utils.c @@ -144,6 +144,9 @@ dumpBabelRestoreChecks(FILE *OPF, PGconn *conn, int binary_upgrade) res = executeQuery(conn, "SELECT setting::INT from pg_settings WHERE name = 'server_version_num';"); source_server_version_num = atoi(PQgetvalue(res, 0, 0)); + /* SET babelfishpg_tsql.dump_restore GUC in the beginning */ + appendPQExpBufferStr(qry, "SET babelfishpg_tsql.dump_restore = TRUE;\n"); + /* * Temporarily enable ON_ERROR_STOP so that whole restore script * execution fails if the following do block raises an error. From 1e4f6fc623b763372ca633f1f5e9551e2cbc5b11 Mon Sep 17 00:00:00 2001 From: Sharu Goel <30777678+thephantomthief@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:15:47 +0530 Subject: [PATCH 2/5] Support adding users to T-SQL db_owner database role (#481) This commit adds support in Babelfish dump utility to dump the linked roles associated with members of db_owner role that are not present in Babelfish catalogs. Task: BABEL-4899 Signed-off-by: Sharu Goel --- src/bin/pg_dump/dumpall_babel_utils.c | 64 +++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/bin/pg_dump/dumpall_babel_utils.c b/src/bin/pg_dump/dumpall_babel_utils.c index a185690d9ef..2427e97b9b7 100644 --- a/src/bin/pg_dump/dumpall_babel_utils.c +++ b/src/bin/pg_dump/dumpall_babel_utils.c @@ -241,6 +241,38 @@ getBabelfishRolesQuery(PGconn *conn, PQExpBuffer buf, char *role_catalog, appendPQExpBuffer(buf, "WHERE database_name = '%s' ", escaped_bbf_db_name); pfree(escaped_bbf_db_name); } + + /* Append roles associated with db_owner members which are not present in bbf catalogs */ + appendPQExpBuffer(buf, + "UNION " + "SELECT pr.rolname " + "FROM ( " + "SELECT DISTINCT pr.rolname AS member_role " + "FROM sys.babelfish_authid_user_ext ta " + "JOIN pg_roles r ON r.rolname = ta.rolname " + "JOIN pg_auth_members m ON r.oid = m.roleid " + "JOIN pg_roles pr ON pr.oid = m.member " + "WHERE pr.rolname != ta.rolname " + "AND ta.orig_username = 'db_owner' "); + + /* Only dump users of the specific logical database we are currently dumping. */ + if (bbf_db_name != NULL) + { + /* + * Get escaped bbf_db_name to handle special characters in it. + * 2*strlen+1 bytes are required for PQescapeString according to the documentation. + */ + char *escaped_bbf_db_name = pg_malloc(2 * strlen(bbf_db_name) + 1); + + PQescapeString(escaped_bbf_db_name, bbf_db_name, strlen(bbf_db_name)); + appendPQExpBuffer(buf, "AND ta.database_name = '%s' ", escaped_bbf_db_name); + pfree(escaped_bbf_db_name); + } + + appendPQExpBuffer(buf, + ") AS db_owner_members " + "JOIN pg_roles pr ON pr.rolname = sys.babelfish_truncate_identifier(db_owner_members.member_role || '_obj') "); + appendPQExpBuffer(buf, "), " "bbf_roles AS (SELECT rc.* FROM %s rc INNER JOIN bbf_catalog bcat " "ON rc.rolname = bcat.rolname) ", role_catalog); @@ -327,6 +359,38 @@ getBabelfishRoleMembershipQuery(PGconn *conn, PQExpBuffer buf, appendPQExpBuffer(buf, "WHERE database_name = '%s' ", escaped_bbf_db_name); pfree(escaped_bbf_db_name); } + + /* Append roles associated with db_owner members which are not present in bbf catalogs */ + appendPQExpBuffer(buf, + "UNION " + "SELECT pr.rolname " + "FROM ( " + "SELECT DISTINCT pr.rolname AS member_role " + "FROM sys.babelfish_authid_user_ext ta " + "JOIN pg_roles r ON r.rolname = ta.rolname " + "JOIN pg_auth_members m ON r.oid = m.roleid " + "JOIN pg_roles pr ON pr.oid = m.member " + "WHERE pr.rolname != ta.rolname " + "AND ta.orig_username = 'db_owner' "); + + /* Only dump users of the specific logical database we are currently dumping. */ + if (bbf_db_name != NULL) + { + /* + * Get escaped bbf_db_name to handle special characters in it. + * 2*strlen+1 bytes are required for PQescapeString according to the documentation. + */ + char *escaped_bbf_db_name = pg_malloc(2 * strlen(bbf_db_name) + 1); + + PQescapeString(escaped_bbf_db_name, bbf_db_name, strlen(bbf_db_name)); + appendPQExpBuffer(buf, "AND ta.database_name = '%s' ", escaped_bbf_db_name); + pfree(escaped_bbf_db_name); + } + + appendPQExpBuffer(buf, + ") AS db_owner_members " + "JOIN pg_roles pr ON pr.rolname = sys.babelfish_truncate_identifier(db_owner_members.member_role || '_obj') "); + appendPQExpBuffer(buf, "), " "bbf_roles AS (SELECT rc.* FROM %s rc INNER JOIN bbf_catalog bcat " "ON rc.rolname = bcat.rolname) ", role_catalog); From 6a6632a162783c35ef621402b557e187828311de Mon Sep 17 00:00:00 2001 From: Rishabh Tanwar <33982749+rishabhtanwar29@users.noreply.github.com> Date: Mon, 25 Nov 2024 09:40:38 +0530 Subject: [PATCH 3/5] Re-enable the assert (#477) The assert in fasthash_accum_cstring was previously disabled due to crash during restore. Re-enable this assert since the related testcase has been updated to fix the issue. Task: BABEL-5421 Signed-off-by: Rishabh Tanwar ritanwar@amazon.com --- src/include/common/hashfn_unstable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/common/hashfn_unstable.h b/src/include/common/hashfn_unstable.h index 7d016c617ca..0adb0f82f9a 100644 --- a/src/include/common/hashfn_unstable.h +++ b/src/include/common/hashfn_unstable.h @@ -348,7 +348,7 @@ fasthash_accum_cstring(fasthash_state *hs, const char *str) { len = fasthash_accum_cstring_aligned(hs, str); Assert(len_check == len); - // TODO: Assert(hs_check.hash == hs->hash); + Assert(hs_check.hash == hs->hash); return len; } #endif /* SIZEOF_VOID_P */ From 23934a685dcc611af7e7a30c7f90027d3ac75bdc Mon Sep 17 00:00:00 2001 From: Shameem Ahmed <54461265+ahmed-shameem@users.noreply.github.com> Date: Tue, 12 Nov 2024 21:09:19 +0530 Subject: [PATCH 4/5] Update automatic tag creation validation for Minor Version (#471) Till now we were considering a digit for tag for all versions. But it is possible that the minor version may go beyond 9, in that case the automatic tag creation workflow will fail at input tag validation step. This commit updates the validation to handle such cases Signed-off-by: Shameem Ahmed shmeeh@amazon.com --- .github/scripts/create-tag.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/create-tag.sh b/.github/scripts/create-tag.sh index 8168c1c8b2e..5700bf5ab4d 100644 --- a/.github/scripts/create-tag.sh +++ b/.github/scripts/create-tag.sh @@ -37,9 +37,9 @@ fi # check the tag format (need manual update when necessary) format=BABEL_ -if ! [[ "$new" =~ "$format"[0-9]_[0-9]_[0-9]__"PG"_[0-9]+_[0-9] ]] +if ! [[ "$new" =~ "$format"[0-9]_[0-9]+_[0-9]__"PG"_[0-9]+_[0-9]+ ]] then - echo "Error: Invalid tag prefix, expected: ${format}____PG__" + echo "Error: Invalid tag prefix, expected: ${format}____PG__" exit 1 fi From 67a72b04c12e218db4f8834db7fe6ca223d1f63c Mon Sep 17 00:00:00 2001 From: Dipesh Dhameliya Date: Tue, 19 Nov 2024 13:32:57 +0530 Subject: [PATCH 5/5] Extend the ability of planner_node_transformer_hook to store the context of expression being processed (#469) Extend the ability of planner_node_transformer_hook to store the context of expression being process. This saved context will be used during planning to transform declared variable either as a Param (if it appears in TargetList) or as a const (all the other places). Extension: https://github.com/babelfish-for-postgresql/babelfish_extensions/pull/3011/ Task: BABEL-5188 Signed-off-by: Dipesh Dhameliya --- src/backend/optimizer/plan/planner.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 75c6b7052d4..25891f8a442 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -1182,6 +1182,10 @@ preprocess_expression(PlannerInfo *root, Node *expr, int kind) if (kind != EXPRKIND_RTFUNC) expr = eval_const_expressions(root, expr); + /* Reset context of expression */ + if(EXPRKIND_TARGET == kind && planner_node_transformer_hook) + (void) planner_node_transformer_hook(root, NULL, -1); + /* * If it's a qual or havingQual, canonicalize it. */