While testing a fix for bug #17823, I discovered that EvalPlanQualStart
failed to copy es_rteperminfos from the parent EState, resulting in
failure if anything in EPQ execution wanted to consult that information.
This led me to conclude that commit
a61b1f748 had been too haphazard
about where to fill es_rteperminfos, and that we need to be sure that
that happens exactly where es_range_table gets filled. So I changed the
signature of ExecInitRangeTable to help ensure that this new requirement
doesn't get missed. (Indeed, pgoutput.c was also failing to fill it.
Maybe we don't ever need it there, but I wouldn't bet on that.)
No test case yet; one will arrive with the fix for #17823.
But that needs to be back-patched, while this fix is HEAD-only.
Discussion: https://postgr.es/m/17823-
b64909cf7d63de84@postgresql.org
* index-entry-making machinery. (There used to be a huge amount of code
* here that basically duplicated execUtils.c ...)
*/
- ExecInitRangeTable(estate, cstate->range_table);
+ ExecInitRangeTable(estate, cstate->range_table, cstate->rteperminfos);
resultRelInfo = target_resultRelInfo = makeNode(ResultRelInfo);
ExecInitResultRelation(estate, resultRelInfo, 1);
- /*
- * Copy the RTEPermissionInfos into estate as well, so that
- * ExecGetInsertedCols() et al will work correctly.
- */
- estate->es_rteperminfos = cstate->rteperminfos;
-
/* Verify the named relation is a valid target for INSERT */
CheckValidResultRel(resultRelInfo, CMD_INSERT);
int i;
/*
- * Do permissions checks and save the list for later use.
+ * Do permissions checks
*/
ExecCheckPermissions(rangeTable, plannedstmt->permInfos, true);
- estate->es_rteperminfos = plannedstmt->permInfos;
/*
* initialize the node's execution state
*/
- ExecInitRangeTable(estate, rangeTable);
+ ExecInitRangeTable(estate, rangeTable, plannedstmt->permInfos);
estate->es_plannedstmt = plannedstmt;
estate->es_part_prune_infos = plannedstmt->partPruneInfos;
rcestate->es_range_table = parentestate->es_range_table;
rcestate->es_range_table_size = parentestate->es_range_table_size;
rcestate->es_relations = parentestate->es_relations;
- rcestate->es_queryEnv = parentestate->es_queryEnv;
rcestate->es_rowmarks = parentestate->es_rowmarks;
+ rcestate->es_rteperminfos = parentestate->es_rteperminfos;
rcestate->es_plannedstmt = parentestate->es_plannedstmt;
rcestate->es_junkFilter = parentestate->es_junkFilter;
rcestate->es_output_cid = parentestate->es_output_cid;
+ rcestate->es_queryEnv = parentestate->es_queryEnv;
/*
* ResultRelInfos needed by subplans are initialized from scratch when the
estate->es_range_table_size = 0;
estate->es_relations = NULL;
estate->es_rowmarks = NULL;
+ estate->es_rteperminfos = NIL;
estate->es_plannedstmt = NULL;
estate->es_part_prune_infos = NIL;
* indexed by rangetable index.
*/
void
-ExecInitRangeTable(EState *estate, List *rangeTable)
+ExecInitRangeTable(EState *estate, List *rangeTable, List *permInfos)
{
/* Remember the range table List as-is */
estate->es_range_table = rangeTable;
+ /* ... and the RTEPermissionInfo List too */
+ estate->es_rteperminfos = permInfos;
+
/* Set size of associated arrays */
estate->es_range_table_size = list_length(rangeTable);
ApplyExecutionData *edata;
EState *estate;
RangeTblEntry *rte;
+ List *perminfos = NIL;
ResultRelInfo *resultRelInfo;
edata = (ApplyExecutionData *) palloc0(sizeof(ApplyExecutionData));
rte->relid = RelationGetRelid(rel->localrel);
rte->relkind = rel->localrel->rd_rel->relkind;
rte->rellockmode = AccessShareLock;
- ExecInitRangeTable(estate, list_make1(rte));
- addRTEPermissionInfo(&estate->es_rteperminfos, rte);
+ addRTEPermissionInfo(&perminfos, rte);
+
+ ExecInitRangeTable(estate, list_make1(rte), perminfos);
edata->targetRelInfo = resultRelInfo = makeNode(ResultRelInfo);
#include "fmgr.h"
#include "nodes/makefuncs.h"
#include "optimizer/optimizer.h"
+#include "parser/parse_relation.h"
#include "replication/logical.h"
#include "replication/logicalproto.h"
#include "replication/origin.h"
{
EState *estate;
RangeTblEntry *rte;
+ List *perminfos = NIL;
estate = CreateExecutorState();
rte->relid = RelationGetRelid(rel);
rte->relkind = rel->rd_rel->relkind;
rte->rellockmode = AccessShareLock;
- ExecInitRangeTable(estate, list_make1(rte));
+
+ addRTEPermissionInfo(&perminfos, rte);
+
+ ExecInitRangeTable(estate, list_make1(rte), perminfos);
estate->es_output_cid = GetCurrentCommandId(false);
extern Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags);
-extern void ExecInitRangeTable(EState *estate, List *rangeTable);
+extern void ExecInitRangeTable(EState *estate, List *rangeTable, List *permInfos);
extern void ExecCloseRangeTableRelations(EState *estate);
extern void ExecCloseResultRelations(EState *estate);