Re: [(known) BUG] DELETE/UPDATE more than one row in partitioned foreign table

From: Manu <manuelreyesbravo(at)gmail(dot)com>
To: Jakub Wartak <jakub(dot)wartak(at)enterprisedb(dot)com>
Cc: Ajit Awekar <ajitpostgres(at)gmail(dot)com>, Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, shihao zhong <zhong950419(at)gmail(dot)com>, Nikita Malakhov <hukutoc(at)gmail(dot)com>, Jehan-Guillaume de Rorthais <jgdr(at)dalibo(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, rhaas(at)postgresql(dot)org
Subject: Re: [(known) BUG] DELETE/UPDATE more than one row in partitioned foreign table
Date: 2026-10-28 18:32:44
Message-ID: 179321236488.520440.320467809486544701@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Jakub,

On Wed, Oct 28, 2026 at 10:12 AM Jakub Wartak
<jakub(dot)wartak(at)enterprisedb(dot)com> wrote:
> postgres=# DELETE FROM fbig WHERE fbig.* IS NULL AND random() <= 1;
> ERROR: attribute 3 of type record has wrong type

Confirmed with V4 on master 126976a8ffc and fcfd2456078, and V3
already had it; master gives no error. A DELETE whose local qual uses
the whole row fails the same way without random() and on a foreign
partition. UPDATE works on a plain foreign table, but on a
foreign partition it fails with "record type has not been registered".

The ForeignScan's fdw_scan_tlist gets two whole-row entries, one typed
fbig and one RECORD: normalize_wholerow_vartype() retypes the qual's
Var (postgres_fdw.c:1515 with V4), so it no longer equal()s the one
from the reltarget and is appended (:1538). setrefs.c matches on
varno/varattno only and takes the first, the fbig one. The comment at
:1507 assumes core's RECORD Var is already there, which is true only
for UPDATE or with row DELETE triggers; with an AFTER DELETE row
trigger the RECORD entry comes first and the DELETE on the plain
foreign table works (on the partition it then fails like UPDATE).

Ajit, I'll set the entry to Ready for Committer once v5 covers this
and passes the eight cases plus the attached case_i_whole_row.sql.txt.

Regards,
Manu

Attachment Content-Type Size
case_i_whole_row.sql.txt text/plain 3.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Sami Imseih 2026-10-28 18:35:47 Re: [PATCH] pgstat: Add helper to drop entries from a stats kind's hash
Previous Message Tom Lane 2026-10-28 17:31:05 Re: O(N^3) planning time in choose_plan_name() since 8c49a484e8e