Take skip header out of a loop in COPY FROM

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Take skip header out of a loop in COPY FROM

Surafel Temesgen

Hello,

Even if skipping header is done only once its checked and skipped in a loop. If I don’t miss something it can be done out side a loop like attached patch

regards

Surafel


outing-skip-header-from-loop-v1.patch (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Take skip header out of a loop in COPY FROM

Heikki Linnakangas
On 22/08/2019 11:31, Surafel Temesgen wrote:
> Hello,
>
> Even if skipping header is done only once its checked and skipped in a
> loop. If I don’t miss something it can be done out side a loop like
> attached patch

You may be on to something, but if we move it to CopyFrom(), as in your
patch, then it won't get executed e.g. from the calls in file_fdw.
file_fdw calls BeginCopyFrom(), followed by NextCopyFrom(); it doesn't
use CopyFrom().

- Heikki


Reply | Threaded
Open this post in threaded view
|

Re: Take skip header out of a loop in COPY FROM

Adam Lee
On Thu, Aug 22, 2019 at 11:48:31AM +0300, Heikki Linnakangas wrote:

> On 22/08/2019 11:31, Surafel Temesgen wrote:
> > Hello,
> >
> > Even if skipping header is done only once its checked and skipped in a
> > loop. If I don’t miss something it can be done out side a loop like
> > attached patch
>
> You may be on to something, but if we move it to CopyFrom(), as in your
> patch, then it won't get executed e.g. from the calls in file_fdw. file_fdw
> calls BeginCopyFrom(), followed by NextCopyFrom(); it doesn't use
> CopyFrom().
>
> - Heikki

Yes.

My next thought is to call unlikely() here, but we don't have it...
https://www.postgresql.org/message-id/CABRT9RC-AUuQL6txxsoOkLxjK1iTpyexpbizRF4Zxny1GXASGg%40mail.gmail.com

--
Adam Lee


Reply | Threaded
Open this post in threaded view
|

Re: Take skip header out of a loop in COPY FROM

Heikki Linnakangas
On 22/08/2019 12:54, Adam Lee wrote:
> My next thought is to call unlikely() here, but we don't have it...
> https://www.postgresql.org/message-id/CABRT9RC-AUuQL6txxsoOkLxjK1iTpyexpbizRF4Zxny1GXASGg%40mail.gmail.com

We do, actually, since commit aa3ca5e3dd in v10.

Not sure it's worth the trouble here. Optimizing COPY in general would
be good, even small speedups there are helpful because everyone uses
COPY, but without some evidence I don't believe particular branch is
even measurable.

- Heikki


Reply | Threaded
Open this post in threaded view
|

Re: Take skip header out of a loop in COPY FROM

Tom Lane-2
Heikki Linnakangas <[hidden email]> writes:
> On 22/08/2019 12:54, Adam Lee wrote:
>> My next thought is to call unlikely() here, but we don't have it...

> We do, actually, since commit aa3ca5e3dd in v10.

> Not sure it's worth the trouble here. Optimizing COPY in general would
> be good, even small speedups there are helpful because everyone uses
> COPY, but without some evidence I don't believe particular branch is
> even measurable.

I concur that there's no reason to think that this if-test has a
measurable performance cost.  We're about to do CopyReadLine which
certainly has way more than one branch's worth of processing in it.

If we want to get involved with sprinkling unlikely() calls into
copy.c, the inner per-character or per-field loops would be the
place to look for wins IMO.

I'm going to mark this CF entry as Returned With Feedback.

                        regards, tom lane