Split copy.c

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: vignesh C <vignesh21(at)gmail(dot)com>
Subject: Split copy.c
Date: 2020-11-02 09:03:29
Message-ID: 8e15b560-f387-7acc-ac90-763986617bfb@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

While looking at the parallel copy patches, it started to annoy me how
large copy.c is. It confuses my little head. (Ok, it's annoyed me many
times in the past, but I haven't done anything about it.)

There isn't much common code between COPY FROM and COPY TO, so I propose
that we split copy.c into two: copyfrom.c and copyto.c. See attached. I
thin that's much nicer.

Usually when I'm looking at COPY, I'm specifically looking at COPY FROM
or COPY TO. There is symmetry between the two, like SendCopyBegin() and
ReceiveCopyBegin(), but more often I drill into the details of either
COPY FROM or TO. And when I need to look at those symmetric cases, I
want to open the two functions side-by-side anyway, so they might as
well be in different files.

There is some code duplication now. BeginCopy() was called by both
BeginCopyFrom() and BeginCopyTo(). I copied the common parts of it to
BeginCopyFrom and BeginCopyTo(), but some of the code was only
applicable to FROM or TO.

I also split/duplicated the CopyStateData struct into CopyFromStateData
and CopyToStateData. Many of the fields were common, but many were not,
and I think some duplication is nicer than a struct where you use some
fields and others are unused. I put the common formatting options into a
new CopyFormatOptions struct.

Moving code around always makes backpatching bug fixes harder, but I
think we should bit the bullet. If the parallel COPY work is committed,
it's going to move things around a lot anyway.

- Heikki

Attachment Content-Type Size
0001-Split-copy.c-into-copyto.c-and-copyfrom.c.patch text/x-patch 274.1 KB


Browse pgsql-hackers by date

  From Date Subject
Next Message Jinbao Chen 2020-11-02 09:16:26 Add table AM 'tid_visible'
Previous Message Ashutosh Bapat 2020-11-02 08:53:57 Re: Enumize logical replication message actions