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

From Tom Lane
Subject Re: BUG #19742: `INTERSECT` under a `UNION ALL` with an empty arm fails with "could not find pathkey item t"
Date
Msg-id 261146.1791064428@sss.pgh.pa.us
Whole thread
In response to BUG #19742: `INTERSECT` under a `UNION ALL` with an empty arm fails with "could not find pathkey item t"  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #19742: `INTERSECT` under a `UNION ALL` with an empty arm fails with "could not find pathkey item t"
Re: BUG #19742: `INTERSECT` under a `UNION ALL` with an empty arm fails with "could not find pathkey item t"
List pgsql-bugs
PG Bug reporting form <noreply@postgresql.org> writes:
> Please see the repro. Seems like a regression; 19beta4 and the current main
> branch both have this error raised, but 18.6 works fine. I ran it with psql

> CREATE TABLE d (a int);
> INSERT INTO d VALUES (1), (1), (2), (NULL), (3);
> SELECT * FROM (SELECT a FROM d INTERSECT ALL SELECT a FROM d
>                UNION ALL SELECT a FROM d WHERE false) s
> WHERE a = 1;
> --   ERROR:  XX000: could not find pathkey item to sort

Bisecting shows this started with

fdda78e361f136ec2b8de579b366c1e66bba1199 is the first bad commit
commit fdda78e361f136ec2b8de579b366c1e66bba1199
Author: David Rowley <drowley@postgresql.org>
Date:   Wed Nov 5 11:48:09 2025 +1300

    Fix possible usage of incorrect UPPERREL_SETOP RelOptInfo
    
    03d40e4b5 allowed dummy UNION [ALL] children to be removed from the plan
    by checking for is_dummy_rel().  That commit neglected to still account
    for the relids from the dummy rel so that the correct UPPERREL_SETOP
    RelOptInfo could be found and used for adding the Paths to.

I suspect that that commit just allowed reaching some pre-existing
mistake, but I've not dug into it.

            regards, tom lane



pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #19741: `avg(double precision)` overflows on cancelling finite inputs whose mean is representable
Next
From: Tom Lane
Date:
Subject: Re: BUG #19739: Parameterized first autocommit statement can have different `transaction_timestamp()` and `statement