| From: | Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
|---|---|
| To: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
| Cc: | Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Michael Paquier <michael(at)paquier(dot)xyz> |
| Subject: | Re: Routed ON CONFLICT inserts broken by partition-local deferrable unique constraints in 19 and master |
| Date: | 2026-09-17 21:08:22 |
| Message-ID: | aqwnMDPBLBQ64Eus@alvherre.pgsql |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On 2026-Sep-01, Zsolt Parragi wrote:
> On Tue, 01 Sep 2026, Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com> wrote:
> > This is a "grouped" version. Also, it handles possible collation
> > issues + provides a set of tests to pin the correct behaviour.
>
> Thanks, this looks better what I had in mind, I would have missed a
> few corner cases this patch covers.
I spent some time with this and ended up with the attached. I don't I
found anything to change, apart from minor edits to the commit message.
I'll probably edit it some more before push, to mention the change of
list_difference() to equal().
The non-deterministic collation aspect mentioned in an XXX comment added
by the patch was a bug in 18 and back, and continues to be a bug after
this patch. That's shown with the following test case:
CREATE COLLATION ci (provider = icu, locale = 'und-u-ks-level2', deterministic = false);
-- First part of test case: ON CONFLICT listing a column works fine.
CREATE TABLE t (x text, y text);
ALTER TABLE t ADD CONSTRAINT t_x_key UNIQUE (x);
CREATE UNIQUE INDEX t_x_ci ON t (x COLLATE ci);
INSERT INTO t VALUES ('a', 'first');
INSERT INTO t VALUES ('A', 'second') ON CONFLICT (x) DO UPDATE SET y = excluded.y;
-- the end result here is ('a', 'second'), showing that ON CONFLICT worked.
SELECT x, y FROM t;
-- repeat, but use ON CONFLICT ON CONSTRAINT. Throws error but shouldn't.
INSERT INTO t VALUES ('A', 'third') ON CONFLICT ON CONSTRAINT t_x_key DO UPDATE SET y = excluded.y;
It's not on this patch to solve this problem, as it's not a new problem.
But we should consider a backpatchable fix at some point.
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"I can't go to a restaurant and order food because I keep looking at the
fonts on the menu. Five minutes later I realize that it's also talking
about food" (Donald Knuth)
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-Tighten-definition-of-ON-CONFLICT-arbiter-index-equi.patch | text/x-diff | 28.6 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Sami Imseih | 2026-09-17 21:28:30 | Re: Reject WAIT FOR earlier in transaction-snapshot mode |
| Previous Message | David Rowley | 2026-09-17 20:55:38 | Re: RANGE partition pruning can still exclude the default partition |