Skip to content

Commit

Permalink
Merge branch 'BABEL_5_X_DEV__PG_17_X' into babel_dep
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshLunagariya committed Nov 26, 2024
2 parents d5a7bf8 + 67a72b0 commit 65cedc3
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/scripts/create-tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}<digit>_<digit>_<digit>__PG_<number>_<digit>"
echo "Error: Invalid tag prefix, expected: ${format}<digit>_<number>_<digit>__PG_<number>_<number>"
exit 1
fi

Expand Down
4 changes: 4 additions & 0 deletions src/backend/optimizer/plan/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
67 changes: 67 additions & 0 deletions src/bin/pg_dump/dumpall_babel_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -238,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);
Expand Down Expand Up @@ -324,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);
Expand Down
2 changes: 1 addition & 1 deletion src/include/common/hashfn_unstable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 65cedc3

Please sign in to comment.