Skip to content

Commit

Permalink
Cache sysadmin oid to save some lookups (#1942)
Browse files Browse the repository at this point in the history
This is continuation of the original PR #1899. We cache the sysadmin role oid and expose it through a hook for engine
code changes

Engine PR: babelfish-for-postgresql/postgresql_modified_for_babelfish#234
Extension PR: #1899
Extension PR: (cache sysadmin oid) #1942

Signed-off-by: Tanzeel Khan <[email protected]>
  • Loading branch information
tanscorpio7 authored Oct 24, 2023
1 parent 3a0259b commit 8739a1e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ static table_variable_satisfies_vacuum_hook_type prev_table_variable_satisfies_v
static table_variable_satisfies_vacuum_horizon_hook_type prev_table_variable_satisfies_vacuum_horizon = NULL;
static drop_relation_refcnt_hook_type prev_drop_relation_refcnt_hook = NULL;
static set_local_schema_for_func_hook_type prev_set_local_schema_for_func_hook = NULL;
static bbf_get_sysadmin_oid_hook_type prev_bbf_get_sysadmin_oid_hook = NULL;

/*****************************************
* Install / Uninstall
Expand Down Expand Up @@ -375,6 +376,9 @@ InstallExtendedHooks(void)

prev_set_local_schema_for_func_hook = set_local_schema_for_func_hook;
set_local_schema_for_func_hook = get_local_schema_for_bbf_functions;

prev_bbf_get_sysadmin_oid_hook = bbf_get_sysadmin_oid_hook;
bbf_get_sysadmin_oid_hook = get_sysadmin_oid;
}

void
Expand Down Expand Up @@ -435,6 +439,7 @@ UninstallExtendedHooks(void)
IsToastClassHook = PrevIsToastClassHook;
drop_relation_refcnt_hook = prev_drop_relation_refcnt_hook;
set_local_schema_for_func_hook = prev_set_local_schema_for_func_hook;
bbf_get_sysadmin_oid_hook = prev_bbf_get_sysadmin_oid_hook;
}

/*****************************************
Expand Down
1 change: 1 addition & 0 deletions contrib/babelfishpg_tsql/src/pltsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,7 @@ extern Oid tsql_get_trigger_rel_oid(Oid object_id);
extern bool pltsql_createFunction(ParseState *pstate, PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context,
ParamListInfo params);
extern Oid get_sys_varcharoid(void);
extern Oid get_sysadmin_oid(void);

typedef struct
{
Expand Down
9 changes: 9 additions & 0 deletions contrib/babelfishpg_tsql/src/pltsql_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern bool restore_tsql_tabletype;

/* To cache oid of sys.varchar */
static Oid sys_varcharoid = InvalidOid;
static Oid sysadmin_oid = InvalidOid;

/*
* Following the rule for locktag fields of advisory locks:
Expand Down Expand Up @@ -1718,6 +1719,14 @@ Oid get_sys_varcharoid(void)
return sys_varcharoid;
}

Oid get_sysadmin_oid(void)
{
if (!OidIsValid(sysadmin_oid))
sysadmin_oid = get_role_oid("sysadmin", true);

return sysadmin_oid;
}

List
*gen_grantschema_subcmds(const char *schema, const char *rolname, bool is_grant, bool with_grant_option, const char *privilege)
{
Expand Down

0 comments on commit 8739a1e

Please sign in to comment.