Re: BUG #19099: Conditional DELETE from partitioned table with non-updatable partition raises internal error - Mailing list pgsql-bugs

From Amit Langote
Subject Re: BUG #19099: Conditional DELETE from partitioned table with non-updatable partition raises internal error
Date
Msg-id CA+HiwqE4y8So7zpDK-HDeSLtm_B7eH6ZdbWD=NYrvznEnkGeBA@mail.gmail.com
Whole thread Raw
In response to Re: BUG #19099: Conditional DELETE from partitioned table with non-updatable partition raises internal error  (Amit Langote <amitlangote09@gmail.com>)
Responses Re: BUG #19099: Conditional DELETE from partitioned table with non-updatable partition raises internal error
List pgsql-bugs
On Thu, Nov 6, 2025 at 7:00 PM Amit Langote <amitlangote09@gmail.com> wrote:
> I looked at a few options, but none seem non-invasive enough for
> back-patching, apart from the first patch I posted. That one makes
> ExecInitModifyTable() not require a ctid to be present to set the root
> partitioned table’s ri_RowIdAttNo, except in the case of MERGE, which
> seems to need it. The corner case that triggers the internal error for
> UPDATE/DELETE doesn’t occur for MERGE now and likely won’t when
> foreign tables eventually gain MERGE support; don't mark my words
> though ;-).

Well, OK, I just had not tried hard enough to see that the same error
happens for MERGE too.

With my patch applied:
EXPLAIN VERBOSE MERGE INTO pt t USING (VALUES (1, 'x'::text)) AS s(a,
b) ON false WHEN MATCHED THEN UPDATE SET b = s.b;
ERROR:  could not find junk ctid column

I have another idea: we can simply recognize the corner condition that
throws this error in ExecInitModifyTable() by checking if
ModifyTable.resultRelations contains only the root partitioned table.
That can only happen for UPDATE, DELETE, or MERGE when all child
relations were excluded.

Patch doing that attached.  Added test cases to file_fdw's suite.

--
Thanks, Amit Langote

Attachment

pgsql-bugs by date:

Previous
From: Tender Wang
Date:
Subject: Re: BUG #19099: Conditional DELETE from partitioned table with non-updatable partition raises internal error
Next
From: Amit Langote
Date:
Subject: Re: BUG #19099: Conditional DELETE from partitioned table with non-updatable partition raises internal error