Re: BUG #15795: ERROR: could not find pathkey item to sort

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: suresh.arsenal29@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2019-05-08T10:33:18Z
Lists: pgsql-bugs
PG Bug reporting form <noreply@postgresql.org> writes:
> Here is query:
> SELECT  DISTINCT  A._id0 as _id0, A._actual_type_name0 as _actual_type_name0
>  FROM  ( (   SELECT  DISTINCT _id as _id0, _actual_type_name as
> _actual_type_name0, name as name0  FROM  hello_world.person  ) union all  ( 
> SELECT  DISTINCT  _id as _id0, _actual_type_name as _actual_type_name0, name
> as name0  FROM  hello_world.person)) as A WHERE ( A.name0  =  A.name0 );

It's politer to provide a self-contained test case, rather than expect us
to reverse-engineer details that might be critical.

For the archives, though, this isn't hard to reproduce:

regression=# create table person(_id int, _actual_type_name text, name text);
CREATE TABLE
regression=# SELECT  DISTINCT  A._id0 as _id0, A._actual_type_name0 as _actual_type_name0
 FROM  ( (   SELECT  DISTINCT _id as _id0, _actual_type_name as
_actual_type_name0, name as name0  FROM  person  ) union all  ( 
SELECT  DISTINCT  _id as _id0, _actual_type_name as _actual_type_name0, name
as name0  FROM  person)) as A WHERE ( A.name0  =  A.name0 );
ERROR:  could not find pathkey item to sort

Curiously, this only fails for me in 9.6 and 10, not earlier or later
branches.

			regards, tom lane



Commits

  1. Repair issues with faulty generation of merge-append plans.

  2. Reduce "X = X" to "X IS NOT NULL", if it's easy to do so.