Skip to content

Commit

Permalink
Do not re-do permission checks on range table for parallel worker (ba…
Browse files Browse the repository at this point in the history
…belfish-for-postgresql#233)

With current design of postgres, workflow of parallel worker looks like something below:

```
-- main node
ExecutorRun
 standard_ExecutorStart
  InitPlan
   ExecCheckRTPerms <-- does the permission check on all the range table entries from planner stmt
 standard_ExecutorRun
  ExecutePlan
  .
  .
  .
  ExecGather
   gather_getnext
    -- spawns initialises and run parallel workers
  .
  .
  .
-- parallel worker
ParallelQueryMain
 ExecutorRun
  standard_ExecutorStart
   InitPlan
    ExecCheckRTPerms <- redo the permission check on same set of table
 standard_ExecutorRun
 .
 .
 .
```
Here, Main worker would not have spawned the worker if there is any permission check failures on any of the range table. And parallel worker is again doing the permission check on same set of tables which is kind of redundant. So this commit avoid that unnecessary permission check.

This change is also helpful when select query or subquery involves T-SQL temp tables. Currently, Babelfish is throwing error like "relation with OID 19401 does not exist" because metadata for temp tables is being stored in ENR metadata (which is backend memory) and is not being shared with parallel worker. So this changes will also avoid such error for temp table from parallel worker.

Task: BABEL-4450
Signed-off-by: Dipesh Dhameliya <[email protected]>
  • Loading branch information
Deepesh125 authored and Dipesh Dhameliya committed Oct 12, 2023
1 parent d6e2f2f commit 8837f5f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/backend/executor/execMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "jit/jit.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "parser/parser.h"
#include "parser/parsetree.h"
#include "storage/bufmgr.h"
#include "storage/lmgr.h"
Expand Down Expand Up @@ -814,9 +815,10 @@ InitPlan(QueryDesc *queryDesc, int eflags)
int i;

/*
* Do permissions checks
* Do permissions checks if not parallel worker
*/
ExecCheckRTPerms(rangeTable, true);
if (!(sql_dialect == SQL_DIALECT_TSQL && IsParallelWorker()))
ExecCheckRTPerms(rangeTable, true);

/*
* initialize the node's execution state
Expand Down

0 comments on commit 8837f5f

Please sign in to comment.