Re: [BUG] Query with postgres fwd deletes more tuples than it should

Etsuro Fujita <etsuro.fujita@gmail.com>

From: Etsuro Fujita <etsuro.fujita@gmail.com>
To: jiaoshuntian@highgo.com
Cc: Daniil Davydov <3danissimo@gmail.com>, pgsql-hackers@lists.postgresql.org
Date: 2025-09-17T11:46:02Z
Lists: pgsql-hackers
On Wed, Sep 17, 2025 at 2:46 PM <jiaoshuntian@highgo.com> wrote:
> I can reproduce the same issue using the script you provided.

This is a known bug.  See discussions in [1], where I proposed a
simple fix for it that disables foreign modifications in problematic
cases as shown by Daniil.

> I think a good way to fix would be to use `(tableoid, ctid)` together as the row
> identifier in row-by-row updates/deletes. This combination is unique
> across partitions and avoids the incorrect behavior, while still keeping
> LIMIT support.

Agreed; actually I created such a fix as well a long time ago, but
unfortunately it has many issues...

Best regards,
Etsuro Fujita

[1] https://www.postgresql.org/message-id/flat/20250718175314.4513c00a%40karst