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

Commit b40fe42

Browse files
committed
Clean up range-table building in copy.c
Commit 804b6b6 added the build of a range table in copy.c to initialize the EState es_range_table since it can be needed in error paths. Unfortunately, that commit didn't appreciate that some code paths might end up not initializing the rte which is used to build the range table. Fix that and clean up a couple others things along the way- build it only once and don't explicitly set it on the !is_from path as it doesn't make any sense there (cstate is palloc0'd, so this isn't an issue from an initializing standpoint either). The prior commit went back to 9.0, but this only goes back to 9.1 as prior to that the range table build happens immediately after building the RTE and therefore doesn't suffer from this issue. Pointed out by Robert.
1 parent 3cc74a3 commit b40fe42

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/backend/commands/copy.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString, uint64 *processed)
785785
bool pipe = (stmt->filename == NULL);
786786
Relation rel;
787787
Oid relid;
788-
RangeTblEntry *rte;
788+
List *range_table = NIL;
789789

790790
/* Disallow COPY to/from file or program except to superusers. */
791791
if (!pipe && !superuser())
@@ -810,6 +810,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString, uint64 *processed)
810810
AclMode required_access = (is_from ? ACL_INSERT : ACL_SELECT);
811811
List *attnums;
812812
ListCell *cur;
813+
RangeTblEntry *rte;
813814

814815
Assert(!stmt->query);
815816

@@ -824,6 +825,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString, uint64 *processed)
824825
rte->relid = RelationGetRelid(rel);
825826
rte->relkind = rel->rd_rel->relkind;
826827
rte->requiredPerms = required_access;
828+
range_table = list_make1(rte);
827829

828830
tupDesc = RelationGetDescr(rel);
829831
attnums = CopyGetAttnums(tupDesc, rel, stmt->attlist);
@@ -837,7 +839,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString, uint64 *processed)
837839
else
838840
rte->selectedCols = bms_add_member(rte->selectedCols, attno);
839841
}
840-
ExecCheckRTPerms(list_make1(rte), true);
842+
ExecCheckRTPerms(range_table, true);
841843
}
842844
else
843845
{
@@ -857,7 +859,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString, uint64 *processed)
857859

858860
cstate = BeginCopyFrom(rel, stmt->filename, stmt->is_program,
859861
stmt->attlist, stmt->options);
860-
cstate->range_table = list_make1(rte);
862+
cstate->range_table = range_table;
861863
*processed = CopyFrom(cstate); /* copy from file to database */
862864
EndCopyFrom(cstate);
863865
}
@@ -866,7 +868,6 @@ DoCopy(const CopyStmt *stmt, const char *queryString, uint64 *processed)
866868
cstate = BeginCopyTo(rel, stmt->query, queryString,
867869
stmt->filename, stmt->is_program,
868870
stmt->attlist, stmt->options);
869-
cstate->range_table = list_make1(rte);
870871
*processed = DoCopyTo(cstate); /* copy from database to file */
871872
EndCopyTo(cstate);
872873
}

0 commit comments

Comments
 (0)