@@ -193,6 +193,9 @@ typedef struct CopyStateData
193
193
* the current line. The CopyReadAttributes functions return arrays of
194
194
* pointers into this buffer. We avoid palloc/pfree overhead by re-using
195
195
* the buffer on each cycle.
196
+ *
197
+ * (In binary COPY FROM, attribute_buf holds the binary data for the
198
+ * current field, while the other variables are not used.)
196
199
*/
197
200
StringInfoData attribute_buf ;
198
201
@@ -3359,12 +3362,19 @@ BeginCopyFrom(ParseState *pstate,
3359
3362
cstate -> cur_attname = NULL ;
3360
3363
cstate -> cur_attval = NULL ;
3361
3364
3362
- /* Set up variables to avoid per-attribute overhead. */
3365
+ /*
3366
+ * Set up variables to avoid per-attribute overhead. attribute_buf is
3367
+ * used in both text and binary modes, but we use line_buf and raw_buf
3368
+ * only in text mode.
3369
+ */
3363
3370
initStringInfo (& cstate -> attribute_buf );
3364
- initStringInfo (& cstate -> line_buf );
3365
- cstate -> line_buf_converted = false;
3366
- cstate -> raw_buf = (char * ) palloc (RAW_BUF_SIZE + 1 );
3367
- cstate -> raw_buf_index = cstate -> raw_buf_len = 0 ;
3371
+ if (!cstate -> binary )
3372
+ {
3373
+ initStringInfo (& cstate -> line_buf );
3374
+ cstate -> line_buf_converted = false;
3375
+ cstate -> raw_buf = (char * ) palloc (RAW_BUF_SIZE + 1 );
3376
+ cstate -> raw_buf_index = cstate -> raw_buf_len = 0 ;
3377
+ }
3368
3378
3369
3379
/* Assign range table, we'll need it in CopyFrom. */
3370
3380
if (pstate )
0 commit comments