Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b803b7d

Browse files
committed
Fill EState.es_rteperminfos more systematically.
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 a61b1f7 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
1 parent e76cbb6 commit b803b7d

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

src/backend/commands/copyfrom.c

+1-7
Original file line numberDiff line numberDiff line change
@@ -757,16 +757,10 @@ CopyFrom(CopyFromState cstate)
757757
* index-entry-making machinery. (There used to be a huge amount of code
758758
* here that basically duplicated execUtils.c ...)
759759
*/
760-
ExecInitRangeTable(estate, cstate->range_table);
760+
ExecInitRangeTable(estate, cstate->range_table, cstate->rteperminfos);
761761
resultRelInfo = target_resultRelInfo = makeNode(ResultRelInfo);
762762
ExecInitResultRelation(estate, resultRelInfo, 1);
763763

764-
/*
765-
* Copy the RTEPermissionInfos into estate as well, so that
766-
* ExecGetInsertedCols() et al will work correctly.
767-
*/
768-
estate->es_rteperminfos = cstate->rteperminfos;
769-
770764
/* Verify the named relation is a valid target for INSERT */
771765
CheckValidResultRel(resultRelInfo, CMD_INSERT);
772766

src/backend/executor/execMain.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -807,15 +807,14 @@ InitPlan(QueryDesc *queryDesc, int eflags)
807807
int i;
808808

809809
/*
810-
* Do permissions checks and save the list for later use.
810+
* Do permissions checks
811811
*/
812812
ExecCheckPermissions(rangeTable, plannedstmt->permInfos, true);
813-
estate->es_rteperminfos = plannedstmt->permInfos;
814813

815814
/*
816815
* initialize the node's execution state
817816
*/
818-
ExecInitRangeTable(estate, rangeTable);
817+
ExecInitRangeTable(estate, rangeTable, plannedstmt->permInfos);
819818

820819
estate->es_plannedstmt = plannedstmt;
821820
estate->es_part_prune_infos = plannedstmt->partPruneInfos;
@@ -2805,11 +2804,12 @@ EvalPlanQualStart(EPQState *epqstate, Plan *planTree)
28052804
rcestate->es_range_table = parentestate->es_range_table;
28062805
rcestate->es_range_table_size = parentestate->es_range_table_size;
28072806
rcestate->es_relations = parentestate->es_relations;
2808-
rcestate->es_queryEnv = parentestate->es_queryEnv;
28092807
rcestate->es_rowmarks = parentestate->es_rowmarks;
2808+
rcestate->es_rteperminfos = parentestate->es_rteperminfos;
28102809
rcestate->es_plannedstmt = parentestate->es_plannedstmt;
28112810
rcestate->es_junkFilter = parentestate->es_junkFilter;
28122811
rcestate->es_output_cid = parentestate->es_output_cid;
2812+
rcestate->es_queryEnv = parentestate->es_queryEnv;
28132813

28142814
/*
28152815
* ResultRelInfos needed by subplans are initialized from scratch when the

src/backend/executor/execUtils.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ CreateExecutorState(void)
121121
estate->es_range_table_size = 0;
122122
estate->es_relations = NULL;
123123
estate->es_rowmarks = NULL;
124+
estate->es_rteperminfos = NIL;
124125
estate->es_plannedstmt = NULL;
125126
estate->es_part_prune_infos = NIL;
126127

@@ -755,11 +756,14 @@ ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
755756
* indexed by rangetable index.
756757
*/
757758
void
758-
ExecInitRangeTable(EState *estate, List *rangeTable)
759+
ExecInitRangeTable(EState *estate, List *rangeTable, List *permInfos)
759760
{
760761
/* Remember the range table List as-is */
761762
estate->es_range_table = rangeTable;
762763

764+
/* ... and the RTEPermissionInfo List too */
765+
estate->es_rteperminfos = permInfos;
766+
763767
/* Set size of associated arrays */
764768
estate->es_range_table_size = list_length(rangeTable);
765769

src/backend/replication/logical/worker.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ create_edata_for_relation(LogicalRepRelMapEntry *rel)
671671
ApplyExecutionData *edata;
672672
EState *estate;
673673
RangeTblEntry *rte;
674+
List *perminfos = NIL;
674675
ResultRelInfo *resultRelInfo;
675676

676677
edata = (ApplyExecutionData *) palloc0(sizeof(ApplyExecutionData));
@@ -683,9 +684,10 @@ create_edata_for_relation(LogicalRepRelMapEntry *rel)
683684
rte->relid = RelationGetRelid(rel->localrel);
684685
rte->relkind = rel->localrel->rd_rel->relkind;
685686
rte->rellockmode = AccessShareLock;
686-
ExecInitRangeTable(estate, list_make1(rte));
687687

688-
addRTEPermissionInfo(&estate->es_rteperminfos, rte);
688+
addRTEPermissionInfo(&perminfos, rte);
689+
690+
ExecInitRangeTable(estate, list_make1(rte), perminfos);
689691

690692
edata->targetRelInfo = resultRelInfo = makeNode(ResultRelInfo);
691693

src/backend/replication/pgoutput/pgoutput.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "fmgr.h"
2424
#include "nodes/makefuncs.h"
2525
#include "optimizer/optimizer.h"
26+
#include "parser/parse_relation.h"
2627
#include "replication/logical.h"
2728
#include "replication/logicalproto.h"
2829
#include "replication/origin.h"
@@ -792,6 +793,7 @@ create_estate_for_relation(Relation rel)
792793
{
793794
EState *estate;
794795
RangeTblEntry *rte;
796+
List *perminfos = NIL;
795797

796798
estate = CreateExecutorState();
797799

@@ -800,7 +802,10 @@ create_estate_for_relation(Relation rel)
800802
rte->relid = RelationGetRelid(rel);
801803
rte->relkind = rel->rd_rel->relkind;
802804
rte->rellockmode = AccessShareLock;
803-
ExecInitRangeTable(estate, list_make1(rte));
805+
806+
addRTEPermissionInfo(&perminfos, rte);
807+
808+
ExecInitRangeTable(estate, list_make1(rte), perminfos);
804809

805810
estate->es_output_cid = GetCurrentCommandId(false);
806811

src/include/executor/executor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ extern bool ExecRelationIsTargetRelation(EState *estate, Index scanrelid);
568568

569569
extern Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags);
570570

571-
extern void ExecInitRangeTable(EState *estate, List *rangeTable);
571+
extern void ExecInitRangeTable(EState *estate, List *rangeTable, List *permInfos);
572572
extern void ExecCloseRangeTableRelations(EState *estate);
573573
extern void ExecCloseResultRelations(EState *estate);
574574

0 commit comments

Comments
 (0)