Re: Assert the timestamp is available for ORIGN_DIFFERS conflicts

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Assert the timestamp is available for ORIGN_DIFFERS conflicts
Date: 2026-01-23 02:59:40
Message-ID: CAA4eK1K_g7bi+6=rut3CFV0rSyBPoFVbZ1k8zeLNRE5SFnmtuA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jan 22, 2026 at 6:30 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>
> > On Jan 21, 2026, at 15:10, Hayato Kuroda (Fujitsu) <kuroda(dot)hayato(at)fujitsu(dot)com> wrote:
> >
> > Dear Shveta,
> >
> > Thanks for ideas, I prefer first one. Also, pgindent told me that Line blank
> > should be before the code comment. PSA the new version.
> >
> > Best regards,
> > Hayato Kuroda
> > FUJITSU LIMITED
> >> Shveta
> > <v2-0001-Add-Assert-for-UPDATE-DELETE-_ORIGIN_DIFFERS.patch>
>
> Hi Hayato-san,
>
> Thanks for the patch. Though the change is simple, I see some problems:
>
> ```
> + /*
> + * We reach this point only if track_commit_timestamp is enabled.
> + * Therefore, localts must contain a valid timestamp.
> + */
> + Assert(localts);
> ```
>
> 1. The same code appears twice, so kinda redundant.
> 2. The comment is unclear. It asserts localts, but the comment talks about GUC track_commit_timestamp.
> 3. Assert(localts) technically works, because C treat un-zero integer as true, but as we are check localts is valid, it’s better to be explicit as Assert(localts != 0).
>
> So, I would suggest add the assert in the very beginning of the function as:
> ```
> /*
> * UPDATE_ORIGIN_DIFFERS and DELETE_ORIGIN_DIFFERS conflicts are only
> * reported when track_commit_timestamp is enabled, and a valid local
> * commit timestamp is available for the conflicting row.
> */
> Assert(type != CT_UPDATE_ORIGIN_DIFFERS && type != CT_DELETE_ORIGIN_DIFFERS || localts != 0);
>

We can follow your suggestion to reduce minor code duplicacy but OTOH
it leads to type specific checks (Assert in this case) which can make
code difficult to follow if we continue such a practice. But your idea
to have a bit more explicit assert like Assert(localts != 0) sounds
okay to me.

--
With Regards,
Amit Kapila.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Yi Ding 2026-01-23 03:13:12 Fix a typo in comment
Previous Message Chao Li 2026-01-23 02:48:44 Re: DOCS - "\d mytable" also shows any publications that publish mytable