Re: Improvements in Copy From - Mailing list pgsql-hackers

From Peter Smith
Subject Re: Improvements in Copy From
Date
Msg-id CAHut+PsPhcpXtcojEh5KOdZTg7eVVSfMh3b8yLkwUKnRSRAUSA@mail.gmail.com
Whole thread Raw
In response to Re: Improvements in Copy From  (vignesh C <vignesh21@gmail.com>)
Responses Re: Improvements in Copy From  (vignesh C <vignesh21@gmail.com>)
List pgsql-hackers
My basic understanding of first part of your patch is that by
adjusting the "minread" it now allows it to loop multiple times
internally within the CopyGetData rather than calling CopyLoadRawBuf
for every N lines. There doesn't seem to be much change to what other
code gets executed so the saving is essentially whatever is the cost
of making 2 x function calls (CopyLoadRawBuff + CopyGetData) x N. Is
that understanding correct?

But with that change there seems to be opportunity for yet another
tiny saving possible. IIUC, now you are processing a lot more data
within the CopyGetData so it is now very likely that you will also
gobble the COPY_NEW_FE's 'c' marker. So cstate->reached_eof will be
set. So this means the calling code of CopyReadLineText may no longer
need to call the CopyLoadRawBuf one last time just to discover there
are no more bytes to read - something that it already knows if
cstate->reached_eof == true.

For example, with your change can't you also modify CopyReadLineText like below:

BEFORE
            if (!CopyLoadRawBuf(cstate))
                hit_eof = true;

AFTER
            if (cstate->reached_eof)
            {
                cstate->raw_buf[0] = '\0';
                cstate->raw_buf_index = cstate->raw_buf_len = 0;
                hit_eof = true;
            }
            else if (!CopyLoadRawBuf(cstate))
            {
                hit_eof = true;
            }

Whether such a micro-optimisation is worth doing is another question.

---

Kind Regards,
Peter Smith.
Fujitsu Australia

On Sun, Aug 30, 2020 at 5:25 PM vignesh C <vignesh21@gmail.com> wrote:
>
> On Thu, Aug 27, 2020 at 11:02 AM Peter Smith <smithpb2250@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



pgsql-hackers by date:

Previous
From: "Andrey M. Borodin"
Date:
Subject: Re: Yet another fast GiST build
Next
From: Darafei "Komяpa" Praliaskouski
Date:
Subject: Re: Yet another fast GiST build