Skip to content

Avoid checking permission of Babelfish temp tables on parallel worker #560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/backend/executor/execMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ ExecutorEnd_hook_type ExecutorEnd_hook = NULL;

TriggerRecuresiveCheck_hook_type TriggerRecuresiveCheck_hook = NULL;
check_rowcount_hook_type check_rowcount_hook = NULL;
skip_ExecutorCheckPerms_hook_type skip_ExecutorCheckPerms_hook = NULL;

/* Hook for plugin to get control in ExecCheckPermissions() */
ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook = NULL;

Expand All @@ -84,7 +86,6 @@ static void ExecutePlan(QueryDesc *queryDesc,
uint64 numberTuples,
ScanDirection direction,
DestReceiver *dest);
static bool ExecCheckOneRelPerms(RTEPermissionInfo *perminfo);
static bool ExecCheckPermissionsModified(Oid relOid, Oid userid,
Bitmapset *modifiedCols,
AclMode requiredPerms);
Expand Down Expand Up @@ -615,6 +616,16 @@ ExecCheckPermissions(List *rangeTable, List *rteperminfos,
RTEPermissionInfo *perminfo = lfirst_node(RTEPermissionInfo, l);

Assert(OidIsValid(perminfo->relid));

/*
* Babelfish specific logic - skip permission check for temp table
* under parallel worker
*/
if (IsBabelfishParallelWorker() &&
skip_ExecutorCheckPerms_hook &&
(*skip_ExecutorCheckPerms_hook)(perminfo->relid))
continue;

result = ExecCheckOneRelPerms(perminfo);
if (!result)
{
Expand All @@ -636,7 +647,7 @@ ExecCheckPermissions(List *rangeTable, List *rteperminfos,
* ExecCheckOneRelPerms
* Check access permissions for a single relation.
*/
static bool
bool
ExecCheckOneRelPerms(RTEPermissionInfo *perminfo)
{
AclMode requiredPerms;
Expand Down Expand Up @@ -840,10 +851,9 @@ InitPlan(QueryDesc *queryDesc, int eflags)
int i;

/*
* Do permissions checks if not Babelfish parallel worker
* Do permissions checks
*/
if (!IsBabelfishParallelWorker())
ExecCheckPermissions(rangeTable, plannedstmt->permInfos, true);
ExecCheckPermissions(rangeTable, plannedstmt->permInfos, true);

/*
* initialize the node's execution state
Expand Down
20 changes: 20 additions & 0 deletions src/backend/executor/execParallel.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ typedef struct ExecParallelInitializeDSMContext
int nnodes;
} ExecParallelInitializeDSMContext;

ExecInitParallelPlan_hook_type ExecInitParallelPlan_hook = NULL;
ParallelQueryMain_hook_type ParallelQueryMain_hook = NULL;

/* Helper functions that run in the parallel leader. */
static char *ExecSerializePlan(Plan *plan, EState *estate);
static bool ExecParallelEstimate(PlanState *planstate,
Expand Down Expand Up @@ -683,6 +686,12 @@ ExecInitParallelPlan(PlanState *planstate, EState *estate,
mul_size(PARALLEL_TUPLE_QUEUE_SIZE, pcxt->nworkers));
shm_toc_estimate_keys(&pcxt->estimator, 1);

/* Give extension a chance to share additional details */
if (ExecInitParallelPlan_hook)
{
(*ExecInitParallelPlan_hook)(estate, pcxt, true);
}

/*
* Give parallel-aware nodes a chance to add to the estimates, and get a
* count of how many PlanState nodes there are.
Expand Down Expand Up @@ -773,6 +782,12 @@ ExecInitParallelPlan(PlanState *planstate, EState *estate,
shm_toc_insert(pcxt->toc, PARALLEL_KEY_WAL_USAGE, walusage_space);
pei->wal_usage = walusage_space;

/* Give extension a chance to share additional details */
if (ExecInitParallelPlan_hook)
{
(*ExecInitParallelPlan_hook)(estate, pcxt,false);
}

/* Set up the tuple queues that the workers will write into. */
pei->tqueue = ExecParallelSetupTupleQueues(pcxt, false);

Expand Down Expand Up @@ -1433,6 +1448,11 @@ ParallelQueryMain(dsm_segment *seg, shm_toc *toc)
area_space = shm_toc_lookup(toc, PARALLEL_KEY_DSA, false);
area = dsa_attach_in_place(area_space, seg);

if (IsBabelfishParallelWorker() && ParallelQueryMain_hook)
{
(*ParallelQueryMain_hook)(toc);
}

/* Start up the executor */
queryDesc->plannedstmt->jitFlags = fpes->jit_flags;
ExecutorStart(queryDesc, fpes->eflags);
Expand Down
4 changes: 0 additions & 4 deletions src/include/access/parallel.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,11 @@ extern void ParallelWorkerMain(Datum main_arg);
/* Below helpers are added to support parallel workers in Babelfish context */
extern bool IsBabelfishParallelWorker(void);

/* Key for BabelfishFixedParallelState */
#define BABELFISH_PARALLEL_KEY_FIXED UINT64CONST(0xBBF0000000000001)

/* Hooks for communicating babelfish related information to parallel worker */
typedef void (*bbf_InitializeParallelDSM_hook_type)(ParallelContext *pcxt, bool estimate);
extern PGDLLIMPORT bbf_InitializeParallelDSM_hook_type bbf_InitializeParallelDSM_hook;

typedef void (*bbf_ParallelWorkerMain_hook_type)(shm_toc *toc);
extern PGDLLIMPORT bbf_ParallelWorkerMain_hook_type bbf_ParallelWorkerMain_hook;


#endif /* PARALLEL_H */
6 changes: 6 additions & 0 deletions src/include/executor/execParallel.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ extern void ExecParallelReinitialize(PlanState *planstate,

extern void ParallelQueryMain(dsm_segment *seg, shm_toc *toc);

typedef void (*ParallelQueryMain_hook_type)(shm_toc *toc);
extern PGDLLIMPORT ParallelQueryMain_hook_type ParallelQueryMain_hook;

typedef void (*ExecInitParallelPlan_hook_type)(EState *estate, ParallelContext *pcxt, bool estimate);
extern PGDLLIMPORT ExecInitParallelPlan_hook_type ExecInitParallelPlan_hook;

#endif /* EXECPARALLEL_H */
4 changes: 4 additions & 0 deletions src/include/executor/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ extern PGDLLIMPORT ExecUpdateResultTypeTL_hook_type ExecUpdateResultTypeTL_hook;
typedef bool (*check_rowcount_hook_type) (int es_processed);
extern PGDLLEXPORT check_rowcount_hook_type check_rowcount_hook;

typedef bool (*skip_ExecutorCheckPerms_hook_type) (Oid relid);
extern PGDLLEXPORT skip_ExecutorCheckPerms_hook_type skip_ExecutorCheckPerms_hook;

/*
* prototypes from functions in execAmi.c
*/
Expand Down Expand Up @@ -224,6 +227,7 @@ extern void standard_ExecutorEnd(QueryDesc *queryDesc);
extern void ExecutorRewind(QueryDesc *queryDesc);
extern bool ExecCheckPermissions(List *rangeTable,
List *rteperminfos, bool ereport_on_violation);
extern bool ExecCheckOneRelPerms(RTEPermissionInfo *perminfo);
extern void CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation,
List *mergeActions);
extern void InitResultRelInfo(ResultRelInfo *resultRelInfo,
Expand Down