On Thu, Aug 27, 2020 at 11:02 AM Peter Smith <smithpb2...@gmail.com> wrote: > > Hello. > > FYI - that patch has conflicts when applied. >
Thanks for letting me know. Attached new patch which is rebased on top of head. Regards, VIgnesh EnterpriseDB: http://www.enterprisedb.com
From a343fe1f8fdf4293d2ef6841e243390b99f29e28 Mon Sep 17 00:00:00 2001 From: Vignesh C <vignes...@gmail.com> Date: Sun, 30 Aug 2020 12:31:12 +0530 Subject: [PATCH v2] Improvements in copy from. There are couple of improvements for copy from in this patch which is detailed below: a) copy from stdin copies lesser amount of data to buffer even though space is available in buffer because minread was passed as 1 to CopyGetData, fixed it by passing the actual space available in buffer, this reduces the frequent call to CopyGetData. b) Copy from reads header line and does nothing for the read line, we need not clear EOL & need not convert to server encoding for the header line. --- src/backend/commands/copy.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index db7d24a..c688baa 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -801,14 +801,18 @@ CopyLoadRawBuf(CopyState cstate) { int nbytes = RAW_BUF_BYTES(cstate); int inbytes; + int minread = 1; /* Copy down the unprocessed data if any. */ if (nbytes > 0) memmove(cstate->raw_buf, cstate->raw_buf + cstate->raw_buf_index, nbytes); + if (cstate->copy_dest == COPY_NEW_FE) + minread = RAW_BUF_SIZE - nbytes; + inbytes = CopyGetData(cstate, cstate->raw_buf + nbytes, - 1, RAW_BUF_SIZE - nbytes); + minread, RAW_BUF_SIZE - nbytes); nbytes += inbytes; cstate->raw_buf[nbytes] = '\0'; cstate->raw_buf_index = 0; @@ -3917,7 +3921,7 @@ CopyReadLine(CopyState cstate) } while (CopyLoadRawBuf(cstate)); } } - else + else if (!(cstate->cur_lineno == 0 && cstate->header_line)) { /* * If we didn't hit EOF, then we must have transferred the EOL marker @@ -3951,8 +3955,9 @@ CopyReadLine(CopyState cstate) } } - /* Done reading the line. Convert it to server encoding. */ - if (cstate->need_transcoding) + /* Done reading the line. Convert it to server encoding if not header. */ + if (cstate->need_transcoding && + !(cstate->cur_lineno == 0 && cstate->header_line)) { char *cvt; -- 1.8.3.1