Re: Routed ON CONFLICT inserts broken by partition-local deferrable unique constraints in 19 and master

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Routed ON CONFLICT inserts broken by partition-local deferrable unique constraints in 19 and master
Date: 2026-08-31 23:47:29
Message-ID: CAN4CZFOLRW1MLida7QibeHWvHEML+mA-0F20f-s4MNHe0kRg2w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 31 Aug 2026, Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com> wrote:
> What I understood - the issue is a little bit wider, it also may
> appear on a named constraint - there it is not checked for both
> `deferrable` and `nulls not distinct` to be matching original index
> itself.

I didn't add tests about this in the patch, but it should also handle
these partition-local cases, e.g.

CREATE TABLE d (a int, b text, CONSTRAINT d_pk PRIMARY KEY (a))
PARTITION BY RANGE (a);
CREATE TABLE d1 PARTITION OF d FOR VALUES FROM (0) TO (100);
ALTER TABLE d1 ADD CONSTRAINT d1_a_def UNIQUE (a) DEFERRABLE;
INSERT INTO d VALUES (1, 'one');
INSERT INTO d VALUES (2, 'two') ON CONFLICT ON CONSTRAINT d_pk DO
UPDATE SET b = EXCLUDED.b;
-- master: ERROR; patched: INSERT 0 1

Also, now that I took another look into this, a somewhat similar PG19
regression exists outside partitions tables, caused by a different
commit (2bc7e886fc1):

CREATE TABLE t (a int, b text, CONSTRAINT t_u UNIQUE (a));
ALTER TABLE t ADD CONSTRAINT t_nnd UNIQUE NULLS NOT DISTINCT (a);
INSERT INTO t VALUES (NULL, 'one');

INSERT INTO t VALUES (NULL, 'two') ON CONFLICT ON CONSTRAINT t_u DO
UPDATE SET b = 'upd';
-- 18: ERROR: duplicate key value violates unique constraint "t_nnd"
-- (named arbiter t_u sees no conflict on NULLs, insert proceeds,
t_nnd rejects)
-- 19: INSERT 0 1 -> table now (NULL, 'upd')
-- (t_nnd silently used as arbiter user never named; error
swallowed, row updated)

But that seems like a different issue requiring a different fix.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-09-01 00:13:32 Re: [PATCH] pageinspect: validate line pointers before using them
Previous Message Michael Paquier 2026-08-31 23:45:51 Re: Use pg_neg_s*_overflow() for open-coded negation overflow checks