Re: [BUG?] check_exclusion_or_unique_constraint false negative

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Mihail Nikalayeu <michail(dot)nikolaev(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>
Subject: Re: [BUG?] check_exclusion_or_unique_constraint false negative
Date: 2025-08-22 10:50:41
Message-ID: CAA4eK1JUvx4nMgoTVtxPWAD3nhwnuBdfXLxSi3Lc+xhk57XwOg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Mar 12, 2025 at 6:36 AM Mihail Nikalayeu
<michail(dot)nikolaev(at)gmail(dot)com> wrote:
>
> Hello, everyone and Peter!
>
> Peter, I have added you because you may be interested in (or already know about) this btree-related issue.
>
> Short description of the problem:
>
> I noticed a concurrency issue in btree index scans that affects SnapshotDirty and SnapshotSelf scan types.
> When using these non-MVCC snapshot types, a scan could miss tuples if concurrent transactions delete existing tuples and insert new one with different TIDs on the same page.
>
> The problem occurs because:
> 1. The scan reads a page and caches its tuples in backend-local storage
> 2. A concurrent transaction deletes a tuple and inserts a new one with a different TID
> 3. The scan misses the new tuple because it was already deleted by a committed transaction and does not pass visibility check
> 4. But new version on the page is missed, because not in cached tuples
>

IIUC, the problem you are worried about can happen with DELETE+INSERT
in the same transaction on the subscriber, right? If so, this should
happen with DELETE and INSERT in a separate transaction as well. If
that happens then we anyway may not be able to detect such an INSERT
if it happens on a page earlier than the current page.

BTW, as the update (or DELETE+INSERT) happens at a later time than the
publisher's update/delete, so once we have the last_write_win
resolution strategy implemented, it is the subscriber operation that
will win. So, the current behavior shouldn't cause any problem.

--
With Regards,
Amit Kapila.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2025-08-22 11:02:34 Re: Potential problem in commit f777d773878 and 4f7f7b03758
Previous Message Maxim Orlov 2025-08-22 10:37:21 Re: Add 64-bit XIDs into PostgreSQL 15