Re: [BUG?] check_exclusion_or_unique_constraint false negative

From: Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>, Peter Geoghegan <pg(at)bowt(dot)ie>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, peter(at)eisentraut(dot)org
Subject: Re: [BUG?] check_exclusion_or_unique_constraint false negative
Date: 2025-09-03 18:20:21
Message-ID: CADzfLwVj9ogzrf2P_H9Xb1z8vLEzBemBxp1nC9wCg4KaOFbvmw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello, Amit!

> Now, I
> would like to know the opinion of others who were involved in the
> initial commit, so added Peter E. to see what he thinks of the same.

Peter answered in [0]:
> I don’t remember. I was just the committer.

I’ve attached a new version of the proposed solution.
The first commit includes tests, some README updates, and an
additional pgbench test that reproduces the issue without explicitly
simulating the wait/resume race. This last test is heavy and isn't
intended to be committed.

Instead of adding extra locking in btree, a more lightweight approach
is used: since we already call GetLatestSnapshot before
table_tuple_lock, we can simply call it before each scan attempt and
use that snapshot for the scan.

As a result:
* MVCC scan will not miss updated tuples, while DirtyScan may
* in both cases, table_tuple_lock will wait for the updating
transaction to commit before retrying
* MVCC scan cannot see not-yet-committed new rows, while DirtyScan
can. However, this does not provide any stronger guarantee: in the
case of INSERT vs INSERT, two parallel inserts are still possible.
DirtyScan only slightly reduces the probability, but if the scan does
not find the row, there is still no guarantee that it won’t be
inserted immediately afterward.

Therefore, the MVCC version appears to provide the same guarantees,
without missing tuples, and with the same performance.

Best regards,
Mikhail.

[0]:
https://discord.com/channels/1258108670710124574/1407753138991009913/1411303541900841090

Attachment Content-Type Size
v11-0002-Fix-logical-replication-conflict-detection-durin.patch application/x-patch 4.6 KB
v11-0001-This-patch-introduces-new-injection-points-and-T.patch application/x-patch 27.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2025-09-03 18:47:25 Re: index prefetching
Previous Message Dmitry Mityugov 2025-09-03 17:37:40 Re: Non-reproducible AIO failure