Assert the timestamp is available for ORIGN_DIFFERS conflicts
Assert the timestamp is available for ORIGN_DIFFERS conflicts
Dear Hackers, This is a fork from [1]. While constructing a conflict message, CT_UPDATE_ORIGIN_DIFFERS and CT_DELETE_ORIGIN_DIFFERS assumes that timestamp for the local commit is always available. Actually, it's valid because they can be detected only with track_commit_timestamp, but source code does not describe anything for it. PSA the patch to add Assert() or it. [1]: https://www.postgresql.org/message-id/TY7PR01MB145540C10F511D9AF40CCB395F58DA%40TY7PR01MB14554.jpnprd01.prod.outlook.com Best regards, Hayato Kuroda FUJITSU LIMITED
Re: Assert the timestamp is available for ORIGN_DIFFERS conflicts
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Wed, Jan 21, 2026 at 10:52 AM Hayato Kuroda (Fujitsu) wrote: > > Dear Hackers, > > This is a fork from [1]. > > While constructing a conflict message, CT_UPDATE_ORIGIN_DIFFERS and > CT_DELETE_ORIGIN_DIFFERS assumes that timestamp for the local commit is always > available. Actually, it's valid because they can be detected only with > track_commit_timestamp, but source code does not describe anything for it. > PSA the patch to add Assert() or it. > > [1]: https://www.postgresql.org/message-id/TY7PR01MB145540C10F511D9AF40CCB395F58DA%40TY7PR01MB14554.jpnprd01.prod.outlook.com > Looks good. Can we tweak the comment slightly? Current: + /* + * This type of conflict can be detected only with enabling + * track_commit_timestamp. + */ + Assert(localts); Suggestion: /* * We reach this point only if track_commit_timestamp is enabled. * Therefore, localts must contain a valid timestamp. */ or /* * This type of conflict can be detected only when track_commit_timestamp * is enabled; therefore, the timestamp must be valid here. */ thanks Shveta
RE: Assert the timestamp is available for ORIGN_DIFFERS conflicts
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
Re: Assert the timestamp is available for ORIGN_DIFFERS conflicts
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Wed, Jan 21, 2026 at 12:40 PM Hayato Kuroda (Fujitsu) 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. > The patch LGTM. thanks Shveta
Re: Assert the timestamp is available for ORIGN_DIFFERS conflicts
От:
Chao Li <li.evan.chao@gmail.com>
Дата:
> On Jan 21, 2026, at 15:10, Hayato Kuroda (Fujitsu) 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 > 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); ``` Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/
Re: Assert the timestamp is available for ORIGN_DIFFERS conflicts
От:
Amit Kapila <amit.kapila16@gmail.com>
Дата:
On Thu, Jan 22, 2026 at 6:30 PM Chao Li wrote: > > > On Jan 21, 2026, at 15:10, Hayato Kuroda (Fujitsu) 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 > > > > 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.
RE: Assert the timestamp is available for ORIGN_DIFFERS conflicts
Dear Amit, Chao, Thanks for giving comments. But I do not want to move the Assert() atop switch-case statements; the function would be dirty for other cases. Attached patch updates condition and comments based on your suggestions. Best regards, Hayato Kuroda FUJITSU LIMITED
Re: Assert the timestamp is available for ORIGN_DIFFERS conflicts
От:
Chao Li <li.evan.chao@gmail.com>
Дата:
> On Jan 23, 2026, at 12:32, Hayato Kuroda (Fujitsu) wrote: > > Dear Amit, Chao, > > Thanks for giving comments. But I do not want to move the Assert() atop > switch-case statements; the function would be dirty for other cases. > Attached patch updates condition and comments based on your suggestions. > > Best regards, > Hayato Kuroda > FUJITSU LIMITED > > Thanks for updating the patch. V3 looks good to me. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/