Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb40fe42

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

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
boolpipe= (stmt->filename==NULL);
786786
Relationrel;
787787
Oidrelid;
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
AclModerequired_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)

[8]ページ先頭

©2009-2025 Movatter.jp