Re: [PATCH v1] Fix initial sync of zero-column published tables

From: Mingjie Gao <mingjie(dot)gmj(at)gmail(dot)com>
To: vignesh C <vignesh21(at)gmail(dot)com>
Cc: Peter Smith <smithpb2250(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH v1] Fix initial sync of zero-column published tables
Date: 2026-11-18 09:15:13
Message-ID: CAL5_ZS2XAh7kXQf+53gmsqRd=cnLwojyuzusn7AOjEDRvS=L_Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Vignesh,

Thanks for the suggestion. I've expanded the commit message to explain
why COPY treats an empty column list as unspecified, the behavior in
text and binary mode, and how tablesync marks the list as explicit.

Attached is v4, rebased on master at f03a0f87963. There are no code
changes from v3. With assertions enabled, the core regression tests,
file_fdw regression test, and subscription TAP suite all passed.

Best regards,
mingjiegao

On Wed, 18 Nov 2026 10:50:14 +0530, vignesh C <vignesh21(at)gmail(dot)com> wrote:
> On Sat, 7 Nov 2026 at 11:43, Mingjie Gao <mingjie(dot)gmj(at)gmail(dot)com> wrote:
> >
> > Hi Peter, Vignesh,
> >
> > Thanks for the review. Attached is v3, based on the same master commit:
> > 77705d1e5a616339c3e92f586bbfa7b6bb562beb.
> >
> > Vignesh wrote:
> > > 1) Can we create the table in publisher and subscriber outside the
> > > loop instead of doing it twice, similarly the publication can be
> > > created outside the loop:
> >
> > Done.
> >
> > > 2) With the first changes, we can truncate the tables instead of dropping them:
> >
> > Done. The subscription is dropped before truncating the tables between
> > modes. Each mode still checks initial sync and an incremental insert.
> >
> > Peter wrote:
> > > Saying publish = 'insert' seems overkill.
> >
> > Removed.
> >
> > > Those could be combined a bit...
> >
> > I've combined the cleanup and tidied the comments, spacing and
> > semicolons as suggested in your attachment. The C code is unchanged
> > from v2.
> >
> > Vignesh wrote:
> > > 3) Till which branch will this patch be applied?
> >
> > I reproduced the text-mode issue on PG10. I haven't reproduced it on
> > the other versions, but the code appears to have the same problem.
> > The binary case appears to be affected from PG16, which added binary
> > initial sync.
> >
> > I think we should backpatch to the affected supported branches. I have
> > only tested the patch on master so far.
> >
> > I tested v3 on master with assertions enabled. The regression tests and
> > the relevant logical replication tests passed.
>
> Thanks for the updated version, the v3 version looks good. One
> suggestion, can we elaborate the commit message something like below:
> When a published table has no columns, initial table synchronization
> passes an empty column list to COPY. COPY cannot distinguish an empty
> list from an unspecified one, and treats NIL as "all columns of the
> target table that are neither dropped nor generated". If the
> subscriber's table has columns, COPY therefore expects input for them
> even though the publisher sends none. In text mode, the empty line
> sent for each row is read as a single empty field. As a result, a
> text-like column receives an empty string instead of its local
> default, while columns of other types fail in their input functions.
> In binary mode, the zero field count does not match the expected
> count, causing synchronization to fail repeatedly with "row field
> count is 0, expected 1".
>
> Fix this by allowing the caller to specify that an empty column list
> is intentional. Add BeginCopyFromExtended(), which takes a flag
> indicating that a NIL attnamelist selects no input columns, and use it
> in tablesync. With no input columns, all subscriber columns are
> filled from their defaults, just as they are when omitted from an
> explicit column list. Keep BeginCopyFrom() as a wrapper that passes
> false, leaving COPY itself and other callers unchanged. Since an
> empty column list cannot be specified in SQL, only tablesync needs
> this distinction.
>
> Regards,
> Vignesh

Attachment Content-Type Size
v4-0001-Fix-initial-sync-of-zero-column-published-tables.patch application/octet-stream 8.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2026-11-18 09:45:49 Re: Fix ReadStream handling when heap rescan strategy changes
Previous Message Henson Choi 2026-11-18 09:06:06 Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements