Skip to content

Commit 88b45aa

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 9406884 commit 88b45aa

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
@@ -738,7 +738,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
738738
bool pipe = (stmt->filename == NULL);
739739
Relation rel;
740740
uint64 processed;
741-
RangeTblEntry *rte;
741+
List *range_table = NIL;
742742

743743
/* Disallow file COPY except to superusers. */
744744
if (!pipe && !superuser())
@@ -754,6 +754,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
754754
AclMode required_access = (is_from ? ACL_INSERT : ACL_SELECT);
755755
List *attnums;
756756
ListCell *cur;
757+
RangeTblEntry *rte;
757758

758759
Assert(!stmt->query);
759760

@@ -766,6 +767,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
766767
rte->relid = RelationGetRelid(rel);
767768
rte->relkind = rel->rd_rel->relkind;
768769
rte->requiredPerms = required_access;
770+
range_table = list_make1(rte);
769771

770772
tupDesc = RelationGetDescr(rel);
771773
attnums = CopyGetAttnums(tupDesc, rel, stmt->attlist);
@@ -779,7 +781,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
779781
else
780782
rte->selectedCols = bms_add_member(rte->selectedCols, attno);
781783
}
782-
ExecCheckRTPerms(list_make1(rte), true);
784+
ExecCheckRTPerms(range_table, true);
783785
}
784786
else
785787
{
@@ -796,15 +798,14 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
796798

797799
cstate = BeginCopyFrom(rel, stmt->filename,
798800
stmt->attlist, stmt->options);
799-
cstate->range_table = list_make1(rte);
801+
cstate->range_table = range_table;
800802
processed = CopyFrom(cstate); /* copy from file to database */
801803
EndCopyFrom(cstate);
802804
}
803805
else
804806
{
805807
cstate = BeginCopyTo(rel, stmt->query, queryString, stmt->filename,
806808
stmt->attlist, stmt->options);
807-
cstate->range_table = list_make1(rte);
808809
processed = DoCopyTo(cstate); /* copy from database to file */
809810
EndCopyTo(cstate);
810811
}

0 commit comments

Comments
 (0)