Re: BUG #19742: `INTERSECT` under a `UNION ALL` with an empty arm fails with "could not find pathkey item t"

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: feasiblechart(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19742: `INTERSECT` under a `UNION ALL` with an empty arm fails with "could not find pathkey item t"
Date: 2026-10-04 05:37:29
Message-ID: CAApHDvreoQsZs=CGNz2GjAsHV=j-tb_ycOHW3EFsBp1TO8BxcA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Sun, 4 Oct 2026 at 14:00, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> and the reason it doesn't fail is that the AppendPath has nil pathkeys
> in this case. So (I speculate that) we never attached pathkeys to a
> UNION ALL AppendPath before, and the reason we're trying to now has
> something to do with having reduced the child list to a singleton.

It looks like a bug in add_setop_child_rel_equivalences(). It wrongly
assumes that setop_pathkeys will contain a PathKey for each tlist
entry. The problem query has a redundant PathKey due to the WHERE a =
1.

I think the fix needs to be either don't remove redundant pathkeys for
setop_pathkeys or use some other method to figure out which
expressions to add in add_child_eq_member().

David

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2026-10-04 05:42:58 Re: BUG #19742: `INTERSECT` under a `UNION ALL` with an empty arm fails with "could not find pathkey item t"
Previous Message shihao zhong 2026-10-04 05:23:29 Re: BUG #19742: `INTERSECT` under a `UNION ALL` with an empty arm fails with "could not find pathkey item t"