Re: pg_decode_message vs skip_empty_xacts and xact_wrote_changes

From: vignesh C <vignesh21(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Subject: Re: pg_decode_message vs skip_empty_xacts and xact_wrote_changes
Date: 2023-07-03 11:19:40
Message-ID: CALDaNm3Hj72XtEcn_nRm4t4c59gaYCJk=-aeaJT47ktoAmBUNQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 30 Jun 2023 at 09:55, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
>
> On Thu, Jun 29, 2023 at 9:40 PM vignesh C <vignesh21(at)gmail(dot)com> wrote:
> >
> > On Thu, 29 Jun 2023 at 09:58, Zhijie Hou (Fujitsu)
> > <houzj(dot)fnst(at)fujitsu(dot)com> wrote:
> > >
> > > On Thursday, June 29, 2023 12:06 PM vignesh C <vignesh21(at)gmail(dot)com> wrote:
> > > >
> > >
> > > Thanks for the patches.
> > >
> > > I tried to understand the following check:
> > >
> > > /*
> > > * If asked to skip empty transactions, we'll emit BEGIN at the point
> > > * where the first operation is received for this transaction.
> > > */
> > > - if (data->skip_empty_xacts)
> > > + if (!(last_write ^ data->skip_empty_xacts) || txndata->xact_wrote_changes)
> > > return;
> > >
> > > I might miss something, but would you mind elaborating on why we use "last_write" in this check?
> >
> > last_write is used to indicate if it is begin/"begin
> > prepare"(last_write is true) or change/truncate/message(last_write is
> > false).
> >
> > We have specified logical XNOR which will be true for the following conditions:
> > Condition1: last_write && data->skip_empty_xacts -> If it is
> > begin/begin prepare and user has specified skip empty transactions, we
> > will return from here, so that the begin message can be appended at
> > the point where the first operation is received for this transaction.
> > Condition2: !last_write && !data->skip_empty_xacts -> If it is
> > change/truncate or message and user has not specified skip empty
> > transactions, we will return from here as we would have appended the
> > begin earlier itself.
> > The txndata->xact_w6rote_changes will be set after the first operation
> > is received for this transaction during which we would have outputted
> > the begin message, this condition is to skip outputting begin message
> > if the begin message was already outputted.
> >
>
> I feel the use of last_write has reduced the readability of this part
> of the code. It may be that we can add comments to make it clear but I
> feel your previous version was much easier to understand.

+1 for the first version patch, I also felt the first version is
easily understandable.

Regards,
Vignesh

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ranier Vilela 2023-07-03 11:26:26 Re: Avoid unncessary always true test (src/backend/storage/buffer/bufmgr.c)
Previous Message Matthias van de Meent 2023-07-03 11:08:31 Re: XLog size reductions: Reduced XLog record header size for PG17