mirror of
https://github.com/postgres/postgres.git
synced 2025-05-24 00:03:23 -04:00
Avoid useless buffer allocations during binary COPY FROM.
The raw_buf and line_buf buffers aren't used when reading binary format, so skip allocating them. raw_buf is 64K so that seems like a worthwhile savings. An unused line_buf only wastes 1K, but as long as we're checking it's free to avoid allocating that too. Bharath Rupireddy, tweaked a bit by me Discussion: https://postgr.es/m/CALj2ACXcCKaGPY0whowqrJ4OPJvDnTssgpGCzvuFQu5z0CXb-g@mail.gmail.com
This commit is contained in:
parent
ea9125304d
commit
cd22d3cdb9
@ -193,6 +193,9 @@ typedef struct CopyStateData
|
|||||||
* the current line. The CopyReadAttributes functions return arrays of
|
* the current line. The CopyReadAttributes functions return arrays of
|
||||||
* pointers into this buffer. We avoid palloc/pfree overhead by re-using
|
* pointers into this buffer. We avoid palloc/pfree overhead by re-using
|
||||||
* the buffer on each cycle.
|
* the buffer on each cycle.
|
||||||
|
*
|
||||||
|
* (In binary COPY FROM, attribute_buf holds the binary data for the
|
||||||
|
* current field, while the other variables are not used.)
|
||||||
*/
|
*/
|
||||||
StringInfoData attribute_buf;
|
StringInfoData attribute_buf;
|
||||||
|
|
||||||
@ -3359,12 +3362,19 @@ BeginCopyFrom(ParseState *pstate,
|
|||||||
cstate->cur_attname = NULL;
|
cstate->cur_attname = NULL;
|
||||||
cstate->cur_attval = NULL;
|
cstate->cur_attval = NULL;
|
||||||
|
|
||||||
/* Set up variables to avoid per-attribute overhead. */
|
/*
|
||||||
|
* Set up variables to avoid per-attribute overhead. attribute_buf is
|
||||||
|
* used in both text and binary modes, but we use line_buf and raw_buf
|
||||||
|
* only in text mode.
|
||||||
|
*/
|
||||||
initStringInfo(&cstate->attribute_buf);
|
initStringInfo(&cstate->attribute_buf);
|
||||||
initStringInfo(&cstate->line_buf);
|
if (!cstate->binary)
|
||||||
cstate->line_buf_converted = false;
|
{
|
||||||
cstate->raw_buf = (char *) palloc(RAW_BUF_SIZE + 1);
|
initStringInfo(&cstate->line_buf);
|
||||||
cstate->raw_buf_index = cstate->raw_buf_len = 0;
|
cstate->line_buf_converted = false;
|
||||||
|
cstate->raw_buf = (char *) palloc(RAW_BUF_SIZE + 1);
|
||||||
|
cstate->raw_buf_index = cstate->raw_buf_len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Assign range table, we'll need it in CopyFrom. */
|
/* Assign range table, we'll need it in CopyFrom. */
|
||||||
if (pstate)
|
if (pstate)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user