diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2020-11-23 10:50:50 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2020-11-23 10:50:50 +0200 |
commit | c532d15dddff14b01fe9ef1d465013cb8ef186df (patch) | |
tree | 856cc79cac8b7e202e2200a3926edc1969eebcdb /contrib/file_fdw/file_fdw.c | |
parent | 17958972fe3bb03454a4b53756b29d65dc285efa (diff) | |
download | postgresql-c532d15dddff14b01fe9ef1d465013cb8ef186df.tar.gz postgresql-c532d15dddff14b01fe9ef1d465013cb8ef186df.zip |
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
Diffstat (limited to 'contrib/file_fdw/file_fdw.c')
-rw-r--r-- | contrib/file_fdw/file_fdw.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c index 072a6dc1c16..994b90d6b4e 100644 --- a/contrib/file_fdw/file_fdw.c +++ b/contrib/file_fdw/file_fdw.c @@ -105,7 +105,7 @@ typedef struct FileFdwExecutionState bool is_program; /* true if filename represents an OS command */ List *options; /* merged COPY options, excluding filename and * is_program */ - CopyState cstate; /* COPY execution state */ + CopyFromState cstate; /* COPY execution state */ } FileFdwExecutionState; /* @@ -655,7 +655,7 @@ fileBeginForeignScan(ForeignScanState *node, int eflags) char *filename; bool is_program; List *options; - CopyState cstate; + CopyFromState cstate; FileFdwExecutionState *festate; /* @@ -677,6 +677,7 @@ fileBeginForeignScan(ForeignScanState *node, int eflags) */ cstate = BeginCopyFrom(NULL, node->ss.ss_currentRelation, + NULL, filename, is_program, NULL, @@ -752,6 +753,7 @@ fileReScanForeignScan(ForeignScanState *node) festate->cstate = BeginCopyFrom(NULL, node->ss.ss_currentRelation, + NULL, festate->filename, festate->is_program, NULL, @@ -1107,7 +1109,7 @@ file_acquire_sample_rows(Relation onerel, int elevel, char *filename; bool is_program; List *options; - CopyState cstate; + CopyFromState cstate; ErrorContextCallback errcallback; MemoryContext oldcontext = CurrentMemoryContext; MemoryContext tupcontext; @@ -1125,7 +1127,7 @@ file_acquire_sample_rows(Relation onerel, int elevel, /* * Create CopyState from FDW options. */ - cstate = BeginCopyFrom(NULL, onerel, filename, is_program, NULL, NIL, + cstate = BeginCopyFrom(NULL, onerel, NULL, filename, is_program, NULL, NIL, options); /* |