diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 492c467698d..ba7b0149d56 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -578,6 +578,7 @@ ExecCheckPermissions(List *rangeTable, List *rteperminfos, { ListCell *l; bool result = true; + Bitmapset *temprelids = NULL; #ifdef USE_ASSERT_CHECKING Bitmapset *indexset = NULL; @@ -587,6 +588,10 @@ ExecCheckPermissions(List *rangeTable, List *rteperminfos, { RangeTblEntry *rte = lfirst_node(RangeTblEntry, l); + /* TODO: Add explaination */ + if (IsBabelfishParallelWorker() && rte->relpersistence == RELPERSISTENCE_TEMP) + temprelids = bms_add_member(temprelids, rte->relid); + if (rte->perminfoindex != 0) { /* Sanity checks */ @@ -615,6 +620,10 @@ ExecCheckPermissions(List *rangeTable, List *rteperminfos, RTEPermissionInfo *perminfo = lfirst_node(RTEPermissionInfo, l); Assert(OidIsValid(perminfo->relid)); + + if (IsBabelfishParallelWorker() && bms_is_member(perminfo->relid, temprelids)) + continue; + result = ExecCheckOneRelPerms(perminfo); if (!result) { @@ -840,10 +849,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 diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index cf44e056a02..0a47f3e7753 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -507,6 +507,7 @@ _outRangeTblEntry(StringInfo str, const RangeTblEntry *node) WRITE_OID_FIELD(relid); WRITE_BOOL_FIELD(inh); WRITE_CHAR_FIELD(relkind); + WRITE_CHAR_FIELD(relpersistence); WRITE_INT_FIELD(rellockmode); WRITE_UINT_FIELD(perminfoindex); WRITE_NODE_FIELD(tablesample); diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index c4d01a441a0..e1e9ca98153 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -358,6 +358,7 @@ _readRangeTblEntry(void) READ_OID_FIELD(relid); READ_BOOL_FIELD(inh); READ_CHAR_FIELD(relkind); + READ_CHAR_FIELD(relpersistence); READ_INT_FIELD(rellockmode); READ_UINT_FIELD(perminfoindex); READ_NODE_FIELD(tablesample); diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 4895cee9944..2288e815479 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -41,6 +41,7 @@ #include "optimizer/plancat.h" #include "optimizer/planner.h" #include "optimizer/tlist.h" +#include "parser/parser.h" #include "parser/parse_clause.h" #include "parser/parsetree.h" #include "partitioning/partbounds.h" @@ -617,7 +618,21 @@ set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel, * for now, bail out if we see a temporary table. */ if (get_rel_persistence(rte->relid) == RELPERSISTENCE_TEMP) + { + /* + * Babelfish Temp tables are created under ENRs which is not + * shared with other backend (with parallel workwer for example). + * Here, we are marking rte->relpersistence = RELPERSISTENCE_TEMP + * for Babelfish temp table so that we can avoid rechecking the + * permission check of Babelfish temp table on Parallel worker. + * This is safe because scanning of temp table won't be done + * under parallel worker. And we have to wait til all the + * optimisation and rewriting is done. + */ + if (sql_dialect == SQL_DIALECT_TSQL) + rte->relpersistence = RELPERSISTENCE_TEMP; return; + } /* * Table sampling can be pushed down to workers if the sample diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 4dcbf9212dd..2e7162f7a7c 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -1539,6 +1539,7 @@ addRangeTableEntry(ParseState *pstate, rte->relid = RelationGetRelid(rel); rte->inh = inh; rte->relkind = rel->rd_rel->relkind; + rte->relpersistence = rel->rd_rel->relpersistence; rte->rellockmode = lockmode; /* diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index ef23f41864b..9c5edb596b6 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -1100,6 +1100,8 @@ typedef struct RangeTblEntry bool inh; /* relation kind (see pg_class.relkind) */ char relkind pg_node_attr(query_jumble_ignore); + /* relation kind (see pg_class.relpersistence) */ + char relpersistence pg_node_attr(query_jumble_ignore); /* lock level that query requires on the rel */ int rellockmode pg_node_attr(query_jumble_ignore); /* index of RTEPermissionInfo entry, or 0 */