Skip to content

Commit c532d15

Browse files
committed
Split copy.c into four files.
Copy.c has grown really large. Split it into more manageable parts: - copy.c now contains only a few functions that are common to COPY FROM and COPY TO. - copyto.c contains code for COPY TO. - copyfrom.c contains code for initializing COPY FROM, and inserting the tuples to the correct table. - copyfromparse.c contains code for reading from the client/file/program, and parsing the input text/CSV/binary format into tuples. All of these parts are fairly complicated, and fairly independent of each other. There is a patch being discussed to implement parallel COPY FROM, which will add a lot of new code to the COPY FROM path, and another patch which would allow INSERTs to use the same multi-insert machinery as COPY FROM, both of which will require refactoring that code. With those two patches, there's going to be a lot of code churn in copy.c anyway, so now seems like a good time to do this refactoring. The CopyStateData struct is also split. All the formatting options, like FORMAT, QUOTE, ESCAPE, are put in a new CopyFormatOption struct, which is used by both COPY FROM and TO. Other state data are kept in separate CopyFromStateData and CopyToStateData structs. Reviewed-by: Soumyadeep Chakraborty, Erik Rijkers, Vignesh C, Andres Freund Discussion: https://www.postgresql.org/message-id/8e15b560-f387-7acc-ac90-763986617bfb%40iki.fi
1 parent 1795897 commit c532d15

File tree

9 files changed

+4841
-4529
lines changed

9 files changed

+4841
-4529
lines changed

contrib/file_fdw/file_fdw.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ typedef struct FileFdwExecutionState
105105
bool is_program; /* true if filename represents an OS command */
106106
List *options; /* merged COPY options, excluding filename and
107107
* is_program */
108-
CopyState cstate; /* COPY execution state */
108+
CopyFromState cstate; /* COPY execution state */
109109
} FileFdwExecutionState;
110110

111111
/*
@@ -655,7 +655,7 @@ fileBeginForeignScan(ForeignScanState *node, int eflags)
655655
char *filename;
656656
bool is_program;
657657
List *options;
658-
CopyState cstate;
658+
CopyFromState cstate;
659659
FileFdwExecutionState *festate;
660660

661661
/*
@@ -677,6 +677,7 @@ fileBeginForeignScan(ForeignScanState *node, int eflags)
677677
*/
678678
cstate = BeginCopyFrom(NULL,
679679
node->ss.ss_currentRelation,
680+
NULL,
680681
filename,
681682
is_program,
682683
NULL,
@@ -752,6 +753,7 @@ fileReScanForeignScan(ForeignScanState *node)
752753

753754
festate->cstate = BeginCopyFrom(NULL,
754755
node->ss.ss_currentRelation,
756+
NULL,
755757
festate->filename,
756758
festate->is_program,
757759
NULL,
@@ -1107,7 +1109,7 @@ file_acquire_sample_rows(Relation onerel, int elevel,
11071109
char *filename;
11081110
bool is_program;
11091111
List *options;
1110-
CopyState cstate;
1112+
CopyFromState cstate;
11111113
ErrorContextCallback errcallback;
11121114
MemoryContext oldcontext = CurrentMemoryContext;
11131115
MemoryContext tupcontext;
@@ -1125,7 +1127,7 @@ file_acquire_sample_rows(Relation onerel, int elevel,
11251127
/*
11261128
* Create CopyState from FDW options.
11271129
*/
1128-
cstate = BeginCopyFrom(NULL, onerel, filename, is_program, NULL, NIL,
1130+
cstate = BeginCopyFrom(NULL, onerel, NULL, filename, is_program, NULL, NIL,
11291131
options);
11301132

11311133
/*

src/backend/commands/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ OBJS = \
2424
constraint.o \
2525
conversioncmds.o \
2626
copy.o \
27+
copyfrom.o \
28+
copyfromparse.o \
29+
copyto.o \
2730
createas.o \
2831
dbcommands.o \
2932
define.o \

0 commit comments

Comments
 (0)