Split copy.c - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Split copy.c
Date
Msg-id 8e15b560-f387-7acc-ac90-763986617bfb@iki.fi
Whole thread Raw
Responses Re: Split copy.c  (Erik Rijkers <er@xs4all.nl>)
Re: Split copy.c  (vignesh C <vignesh21@gmail.com>)
Re: Split copy.c  (Andres Freund <andres@anarazel.de>)
List 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

pgsql-hackers by date:

Previous
From: Ashutosh Bapat
Date:
Subject: Re: Enumize logical replication message actions
Next
From: Jinbao Chen
Date:
Subject: Add table AM 'tid_visible'