diff --git a/src/backend/distributed/planner/merge_planner.c b/src/backend/distributed/planner/merge_planner.c index 213e914d9..635303764 100644 --- a/src/backend/distributed/planner/merge_planner.c +++ b/src/backend/distributed/planner/merge_planner.c @@ -31,6 +31,7 @@ #include "distributed/pg_version_constants.h" #include "distributed/query_pushdown_planning.h" #include "distributed/query_colocation_checker.h" +#include "distributed/relation_utils.h" #include "distributed/repartition_executor.h" #include "distributed/shared_library_init.h" #include "distributed/shard_pruning.h" @@ -824,6 +825,21 @@ ConvertRelationRTEIntoSubquery(Query *mergeQuery, RangeTblEntry *sourceRte, RangeTblEntry *newRangeTableEntry = copyObject(sourceRte); sourceResultsQuery->rtable = list_make1(newRangeTableEntry); +#if PG_VERSION_NUM >= PG_VERSION_16 + sourceResultsQuery->rteperminfos = NIL; + if (newRangeTableEntry->perminfoindex != 0) + { + /* create permission info for newRangeTableEntry */ + RTEPermissionInfo *perminfo = GetFilledPermissionInfo(newRangeTableEntry->relid, + newRangeTableEntry->inh, + CMD_SELECT); + + /* update the subquery's rteperminfos accordingly */ + newRangeTableEntry->perminfoindex = 1; + sourceResultsQuery->rteperminfos = list_make1(perminfo); + } +#endif + /* set the FROM expression to the subquery */ newRangeTableRef->rtindex = SINGLE_RTE_INDEX; sourceResultsQuery->jointree = makeFromExpr(list_make1(newRangeTableRef), NULL);