Clean up range-table building in copy.c
Commit 804b6b6db4dcfc590a468e7be390738f9f7755fb 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.
This commit is contained in:
parent
d49f84b084
commit
8e36028fcc
@ -748,7 +748,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
|
||||
bool pipe = (stmt->filename == NULL);
|
||||
Relation rel;
|
||||
uint64 processed;
|
||||
RangeTblEntry *rte;
|
||||
List *range_table = NIL;
|
||||
|
||||
/* Disallow file COPY except to superusers. */
|
||||
if (!pipe && !superuser())
|
||||
@ -764,6 +764,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
|
||||
AclMode required_access = (is_from ? ACL_INSERT : ACL_SELECT);
|
||||
List *attnums;
|
||||
ListCell *cur;
|
||||
RangeTblEntry *rte;
|
||||
|
||||
Assert(!stmt->query);
|
||||
|
||||
@ -776,6 +777,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
|
||||
rte->relid = RelationGetRelid(rel);
|
||||
rte->relkind = rel->rd_rel->relkind;
|
||||
rte->requiredPerms = required_access;
|
||||
range_table = list_make1(rte);
|
||||
|
||||
tupDesc = RelationGetDescr(rel);
|
||||
attnums = CopyGetAttnums(tupDesc, rel, stmt->attlist);
|
||||
@ -789,7 +791,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
|
||||
else
|
||||
rte->selectedCols = bms_add_member(rte->selectedCols, attno);
|
||||
}
|
||||
ExecCheckRTPerms(list_make1(rte), true);
|
||||
ExecCheckRTPerms(range_table, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -808,7 +810,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
|
||||
|
||||
cstate = BeginCopyFrom(rel, stmt->filename,
|
||||
stmt->attlist, stmt->options);
|
||||
cstate->range_table = list_make1(rte);
|
||||
cstate->range_table = range_table;
|
||||
processed = CopyFrom(cstate); /* copy from file to database */
|
||||
EndCopyFrom(cstate);
|
||||
}
|
||||
@ -816,7 +818,6 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
|
||||
{
|
||||
cstate = BeginCopyTo(rel, stmt->query, queryString, stmt->filename,
|
||||
stmt->attlist, stmt->options);
|
||||
cstate->range_table = list_make1(rte);
|
||||
processed = DoCopyTo(cstate); /* copy from database to file */
|
||||
EndCopyTo(cstate);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user