RE: Avoid retaining conflict-related data when no tables are subscribed

From: "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>
Subject: RE: Avoid retaining conflict-related data when no tables are subscribed
Date: 2025-09-05 09:30:15
Message-ID: TY4PR01MB1690712661FEB7238440D6C369403A@TY4PR01MB16907.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thursday, September 4, 2025 7:38 PM Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
>
> On Tue, Sep 2, 2025 at 10:51 AM Zhijie Hou (Fujitsu) <houzj(dot)fnst(at)fujitsu(dot)com>
> wrote:
> >
> > On Friday, August 29, 2025 12:05 PM Amit Kapila
> <amit(dot)kapila16(at)gmail(dot)com> wrote:
> > >
> > > bool
> > > -AllTablesyncsReady(void)
> > > +AllTablesyncsReady(bool ready_if_no_tables)
> > >
> > > This change serves the purpose but I find it makes the API complex
> > > to understand because now it needs to make decisions based on
> > > different states depending on the boolean parameter passed. Can we
> > > introduce a new API for the empty subscription case?
> >
> > Added a new function HasSubscriptionRelationsCached() as suggested.
> >
>
> Thanks, the new API looks better. I have a question related to one of the
> comments:

Thanks for the comments.

>
> *
> Although
> +   * it seems feasible to skip all phases and directly assign
> +candidate_xid to
> +   * oldest_nonremovable_xid in the RDT_GET_CANDIDATE_XID phase
> when no
> +tables
> +   * are currently subscribed, this approach is unsafe. This is because
> +new
> +   * tables may be added to the subscription after the initial table
> +check,
> +   * requiring tuples deleted before candidate_xid for conflict
> +detection in
> +   * upcoming transactions.
>
> --
>
> How is it possible that new tables added will have any data (deleted data in
> this case) from a transaction prior to the candidate_xid transaction?

I initially considered the scenario where a table is created on the subscriber,
and a user deletes a row before adding the table to the subscription. Upon
reconsideration, it appears that retention is not guaranteed prior to table
addition.

However, after analyzing it further, there are some other reasons for checking
the subscription table in the final phase. The comments have been updated
accordingly to reflect the reasons. Please refer to the comments in the new
patch version for details.

> * Can we add a test to show that dead tuples are not retained even with
> retain_dead_tuples=true when subscription has no relations?

Yes, I have added a test for this.

Here is the V3 patch. I merged two patches because they
are both related to conflict data retention.

Best Regards,
Hou zj

Attachment Content-Type Size
v3-0001-Post-commit-review-fixes-for-228c370.patch application/octet-stream 7.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Joel Jacobson 2025-09-05 09:38:33 Re: Proposal: Out-of-Order NOTIFY via GUC to Improve LISTEN/NOTIFY Throughput
Previous Message Dilip Kumar 2025-09-05 09:29:30 Re: Parallel Apply