diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2018-05-22 13:32:52 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2018-05-22 13:32:52 -0400 |
commit | c92d1461e10799c20e10582127dbbd6cb50e9de3 (patch) | |
tree | bf6a37bfae4b6c7ff8f6d004184ff5385ef2ccb5 /src/backend/commands/copy.c | |
parent | cf516dc9d69052360f1de390636c220797120d28 (diff) | |
download | postgresql-c92d1461e10799c20e10582127dbbd6cb50e9de3.tar.gz postgresql-c92d1461e10799c20e10582127dbbd6cb50e9de3.zip |
Widen COPY FROM's current-line-number counter from 32 to 64 bits.
Because the code for the HEADER option skips a line when this counter
is zero, a very long COPY FROM WITH HEADER operation would drop a line
every 2^32 lines. A lesser but still unfortunate problem is that errors
would show a wrong input line number for errors occurring beyond the
2^31'st input line. While such large input streams seemed impractical
when this code was first written, they're not any more. Widening the
counter (and some associated variables) to uint64 should be enough to
prevent problems for the foreseeable future.
David Rowley
Discussion: https://postgr.es/m/CAKJS1f88yh-6wwEfO6QLEEvH3BEugOq2QX1TOja0vCauoynmOQ@mail.gmail.com
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r-- | src/backend/commands/copy.c | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 00b64e53204..05e05b8fb58 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -136,7 +136,7 @@ typedef struct CopyStateData /* these are just for error messages, see CopyFromErrorCallback */ const char *cur_relname; /* table name for error messages */ - int cur_lineno; /* line number for error messages */ + uint64 cur_lineno; /* line number for error messages */ const char *cur_attname; /* current att for error messages */ const char *cur_attval; /* current att value for error messages */ @@ -309,7 +309,7 @@ static void CopyFromInsertBatch(CopyState cstate, EState *estate, ResultRelInfo *resultRelInfo, TupleTableSlot *myslot, BulkInsertState bistate, int nBufferedTuples, HeapTuple *bufferedTuples, - int firstBufferedLineNo); + uint64 firstBufferedLineNo); static bool CopyReadLine(CopyState cstate); static bool CopyReadLineText(CopyState cstate); static int CopyReadAttributesText(CopyState cstate); @@ -2174,17 +2174,21 @@ void CopyFromErrorCallback(void *arg) { CopyState cstate = (CopyState) arg; + char curlineno_str[32]; + + snprintf(curlineno_str, sizeof(curlineno_str), UINT64_FORMAT, + cstate->cur_lineno); if (cstate->binary) { /* can't usefully display the data */ if (cstate->cur_attname) - errcontext("COPY %s, line %d, column %s", - cstate->cur_relname, cstate->cur_lineno, + errcontext("COPY %s, line %s, column %s", + cstate->cur_relname, curlineno_str, cstate->cur_attname); else - errcontext("COPY %s, line %d", - cstate->cur_relname, cstate->cur_lineno); + errcontext("COPY %s, line %s", + cstate->cur_relname, curlineno_str); } else { @@ -2194,16 +2198,16 @@ CopyFromErrorCallback(void *arg) char *attval; attval = limit_printout_length(cstate->cur_attval); - errcontext("COPY %s, line %d, column %s: \"%s\"", - cstate->cur_relname, cstate->cur_lineno, + errcontext("COPY %s, line %s, column %s: \"%s\"", + cstate->cur_relname, curlineno_str, cstate->cur_attname, attval); pfree(attval); } else if (cstate->cur_attname) { /* error is relevant to a particular column, value is NULL */ - errcontext("COPY %s, line %d, column %s: null input", - cstate->cur_relname, cstate->cur_lineno, + errcontext("COPY %s, line %s, column %s: null input", + cstate->cur_relname, curlineno_str, cstate->cur_attname); } else @@ -2224,14 +2228,14 @@ CopyFromErrorCallback(void *arg) char *lineval; lineval = limit_printout_length(cstate->line_buf.data); - errcontext("COPY %s, line %d: \"%s\"", - cstate->cur_relname, cstate->cur_lineno, lineval); + errcontext("COPY %s, line %s: \"%s\"", + cstate->cur_relname, curlineno_str, lineval); pfree(lineval); } else { - errcontext("COPY %s, line %d", - cstate->cur_relname, cstate->cur_lineno); + errcontext("COPY %s, line %s", + cstate->cur_relname, curlineno_str); } } } @@ -2301,7 +2305,7 @@ CopyFrom(CopyState cstate) #define MAX_BUFFERED_TUPLES 1000 HeapTuple *bufferedTuples = NULL; /* initialize to silence warning */ Size bufferedTuplesSize = 0; - int firstBufferedLineNo = 0; + uint64 firstBufferedLineNo = 0; Assert(cstate->rel); @@ -2902,11 +2906,11 @@ CopyFromInsertBatch(CopyState cstate, EState *estate, CommandId mycid, int hi_options, ResultRelInfo *resultRelInfo, TupleTableSlot *myslot, BulkInsertState bistate, int nBufferedTuples, HeapTuple *bufferedTuples, - int firstBufferedLineNo) + uint64 firstBufferedLineNo) { MemoryContext oldcontext; int i; - int save_cur_lineno; + uint64 save_cur_lineno; /* * Print error context information correctly, if one of the operations |