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

Commit588edd8

Browse files
committed
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 counteris zero, a very long COPY FROM WITH HEADER operation would drop a lineevery 2^32 lines. A lesser but still unfortunate problem is that errorswould show a wrong input line number for errors occurring beyond the2^31'st input line. While such large input streams seemed impracticalwhen this code was first written, they're not any more. Widening thecounter (and some associated variables) to uint64 should be enough toprevent problems for the foreseeable future.David RowleyDiscussion:https://postgr.es/m/CAKJS1f88yh-6wwEfO6QLEEvH3BEugOq2QX1TOja0vCauoynmOQ@mail.gmail.com
1 parent7a0aa8d commit588edd8

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

‎src/backend/commands/copy.c‎

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ typedef struct CopyStateData
133133

134134
/* these are just for error messages, see CopyFromErrorCallback */
135135
constchar*cur_relname;/* table name for error messages */
136-
intcur_lineno;/* line number for error messages */
136+
uint64cur_lineno;/* line number for error messages */
137137
constchar*cur_attname;/* current att for error messages */
138138
constchar*cur_attval;/* current att value for error messages */
139139

@@ -298,7 +298,7 @@ static void CopyFromInsertBatch(CopyState cstate, EState *estate,
298298
ResultRelInfo*resultRelInfo,TupleTableSlot*myslot,
299299
BulkInsertStatebistate,
300300
intnBufferedTuples,HeapTuple*bufferedTuples,
301-
intfirstBufferedLineNo);
301+
uint64firstBufferedLineNo);
302302
staticboolCopyReadLine(CopyStatecstate);
303303
staticboolCopyReadLineText(CopyStatecstate);
304304
staticintCopyReadAttributesText(CopyStatecstate);
@@ -2146,17 +2146,21 @@ void
21462146
CopyFromErrorCallback(void*arg)
21472147
{
21482148
CopyStatecstate= (CopyState)arg;
2149+
charcurlineno_str[32];
2150+
2151+
snprintf(curlineno_str,sizeof(curlineno_str),UINT64_FORMAT,
2152+
cstate->cur_lineno);
21492153

21502154
if (cstate->binary)
21512155
{
21522156
/* can't usefully display the data */
21532157
if (cstate->cur_attname)
2154-
errcontext("COPY %s, line %d, column %s",
2155-
cstate->cur_relname,cstate->cur_lineno,
2158+
errcontext("COPY %s, line %s, column %s",
2159+
cstate->cur_relname,curlineno_str,
21562160
cstate->cur_attname);
21572161
else
2158-
errcontext("COPY %s, line %d",
2159-
cstate->cur_relname,cstate->cur_lineno);
2162+
errcontext("COPY %s, line %s",
2163+
cstate->cur_relname,curlineno_str);
21602164
}
21612165
else
21622166
{
@@ -2166,16 +2170,16 @@ CopyFromErrorCallback(void *arg)
21662170
char*attval;
21672171

21682172
attval=limit_printout_length(cstate->cur_attval);
2169-
errcontext("COPY %s, line %d, column %s: \"%s\"",
2170-
cstate->cur_relname,cstate->cur_lineno,
2173+
errcontext("COPY %s, line %s, column %s: \"%s\"",
2174+
cstate->cur_relname,curlineno_str,
21712175
cstate->cur_attname,attval);
21722176
pfree(attval);
21732177
}
21742178
elseif (cstate->cur_attname)
21752179
{
21762180
/* error is relevant to a particular column, value is NULL */
2177-
errcontext("COPY %s, line %d, column %s: null input",
2178-
cstate->cur_relname,cstate->cur_lineno,
2181+
errcontext("COPY %s, line %s, column %s: null input",
2182+
cstate->cur_relname,curlineno_str,
21792183
cstate->cur_attname);
21802184
}
21812185
else
@@ -2196,14 +2200,14 @@ CopyFromErrorCallback(void *arg)
21962200
char*lineval;
21972201

21982202
lineval=limit_printout_length(cstate->line_buf.data);
2199-
errcontext("COPY %s, line %d: \"%s\"",
2200-
cstate->cur_relname,cstate->cur_lineno,lineval);
2203+
errcontext("COPY %s, line %s: \"%s\"",
2204+
cstate->cur_relname,curlineno_str,lineval);
22012205
pfree(lineval);
22022206
}
22032207
else
22042208
{
2205-
errcontext("COPY %s, line %d",
2206-
cstate->cur_relname,cstate->cur_lineno);
2209+
errcontext("COPY %s, line %s",
2210+
cstate->cur_relname,curlineno_str);
22072211
}
22082212
}
22092213
}
@@ -2271,7 +2275,7 @@ CopyFrom(CopyState cstate)
22712275
#defineMAX_BUFFERED_TUPLES 1000
22722276
HeapTuple*bufferedTuples=NULL;/* initialize to silence warning */
22732277
SizebufferedTuplesSize=0;
2274-
intfirstBufferedLineNo=0;
2278+
uint64firstBufferedLineNo=0;
22752279

22762280
Assert(cstate->rel);
22772281

@@ -2627,11 +2631,11 @@ CopyFromInsertBatch(CopyState cstate, EState *estate, CommandId mycid,
26272631
inthi_options,ResultRelInfo*resultRelInfo,
26282632
TupleTableSlot*myslot,BulkInsertStatebistate,
26292633
intnBufferedTuples,HeapTuple*bufferedTuples,
2630-
intfirstBufferedLineNo)
2634+
uint64firstBufferedLineNo)
26312635
{
26322636
MemoryContextoldcontext;
26332637
inti;
2634-
intsave_cur_lineno;
2638+
uint64save_cur_lineno;
26352639

26362640
/*
26372641
* Print error context information correctly, if one of the operations

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp