Re: doubt about FullTransactionIdAdvance()

From: Zhang Mingli <zmlpostgres(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: doubt about FullTransactionIdAdvance()
Date: 2022-10-24 03:29:54
Message-ID: e4862f61-2a58-43e9-923d-23bdd51dccd6@Spark
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, Andres

On Oct 24, 2022, 01:16 +0800, Andres Freund <andres(at)anarazel(dot)de>, wrote:
> Hi,
>
> On 2022-10-22 11:32:47 +0800, Zhang Mingli wrote:
> > Hi, hackers
> >
> > I don't quite understand FullTransactionIdAdvance(), correct me if I’m wrong.
> >
> >
> > /*
> >  * Advance a FullTransactionId variable, stepping over xids that would appear
> >  * to be special only when viewed as 32bit XIDs.
> >  */
> > static inline void
> > FullTransactionIdAdvance(FullTransactionId *dest)
> > {
> > dest->value++;
> >
> > /* see FullTransactionIdAdvance() */
> > if (FullTransactionIdPrecedes(*dest, FirstNormalFullTransactionId))
> >  return;
> >
> > while (XidFromFullTransactionId(*dest) < FirstNormalTransactionId)
> >  dest->value++;
> > }
> >
> > #define XidFromFullTransactionId(x) ((x).value)
> > #define FullTransactionIdPrecedes(a, b) ((a).value < (b).value)
> >
> > Can the codes reach line: while (XidFromFullTransactionId(*dest) < FirstNormalTransactionId)?
> > As we will return if (FullTransactionIdPrecedes(*dest, FirstNormalFullTransactionId)), and the two judgements seem equal.
> > Another confusion is the comments: /* see FullTransactionIdAdvance() */, is its own  itself.
> > Could anyone explain this? Thanks in advance.
>
> FullTransactionId is 64bit. An "old school" xid is 32bit. The first branch is
> to protect against the special fxids that are actually below
> FirstNormalFullTransactionId:
>
> if (FullTransactionIdPrecedes(*dest, FirstNormalFullTransactionId))
> return;
>
> The second branch is to protect against 64bit xids that would yield a 32bit
> xid below FirstNormalTransactionId after truncating to 32bit:
>
> while (XidFromFullTransactionId(*dest) < FirstNormalTransactionId)
> dest->value++;
>
> E.g. we don't want to modify the 64bit xid 0 (meaning InvalidTransactionId) as
> it has special meaning. But we have to make sure that e.g. the 64bit xid
> 0x100000000 won't exist, as it'd also result in InvalidTransactionId if
> truncated to 32bit.
>
>
> However, it looks like this comment:
> /* see FullTransactionIdAdvance() */
> if (FullTransactionIdPrecedes(*dest, FirstNormalFullTransactionId))
> return;
>
> is bogus, and it's my fault. Looks like it's intending to reference
> FullTransactionIdRetreat().
>
> Greetings,
>
> Andres Freund
Now I get it, thanks for your explanation.

Regards,
Zhang Mingli

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2022-10-24 03:34:32 Re: Patch proposal: make use of regular expressions for the username in pg_hba.conf
Previous Message Tom Lane 2022-10-24 02:51:00 Re: csv_populate_recordset and csv_agg