Re: Conflict detection for multiple_unique_conflicts in logical replication

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>
Cc: Peter Smith <smithpb2250(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
Subject: Re: Conflict detection for multiple_unique_conflicts in logical replication
Date: 2025-03-17 09:49:50
Message-ID: CAA4eK1K0kEt+wQVQd6ySdEb-BbCo93UoY=BPXJ7+rK4Ff3nW1A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Mar 13, 2025 at 4:30 PM Nisha Moond <nisha(dot)moond412(at)gmail(dot)com> wrote:
>
> Attached is the v4 patch (test case changes only).
>

Comments:
=========
1.
+ /*
+ * Report an INSERT_EXISTS or UPDATE_EXISTS conflict when only one unique
+ * constraint is violated.
+ */
+ if (conflicts == 1)
+ {
+ Oid uniqueidx;
+ RepOriginId origin;
+ TimestampTz committs;
+ TransactionId xmin;
+
+ uniqueidx = linitial_oid(conflictIndexes);
+ conflictslot = linitial(conflictSlots);
+
+ GetTupleTransactionInfo(conflictslot, &xmin, &origin, &committs);
+ ReportApplyConflict(estate, resultRelInfo, ERROR, type,
+ searchslot, conflictslot, remoteslot,
+ uniqueidx, xmin, origin, committs);
+ }
+
+ /*
+ * Report MULTIPLE_UNIQUE_CONFLICTS when two or more unique constraints
+ * are violated.
+ */
+ else if (conflicts > 1)
+ ReportMultipleUniqueConflict(estate, resultRelInfo, ERROR,
+ CT_MULTIPLE_UNIQUE_CONFLICTS,
+ searchslot, remoteslot,
+ conflictSlots, conflictIndexes);

It looks a bit odd to have different functions for one or multiple
conflicts. We can improve this coding pattern by extending the current
function ReportApplyConflict to report one or multiple conflicts
depending on the length of conflictSlots.

2. From the commit message: "Also, the patch adds a new column
'confl_multiple_unique_conflicts' in view pg_stat_subscription_stats
to support stats collection for this conflict type.". This part can be
split into a second patch. Let's try to get the core patch first.

--
With Regards,
Amit Kapila.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Anthonin Bonnefoy 2025-03-17 09:50:50 Re: Add Pipelining support in psql
Previous Message Steven Niu 2025-03-17 09:48:06 Re: Forbid to DROP temp tables of other sessions