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

The Post Office <noreply@postgresql.org>

From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: suresh.arsenal29@gmail.com
Date: 2019-05-08T06:51:32Z
Lists: pgsql-bugs
The following bug has been logged on the website:

Bug reference:      15795
Logged by:          Suresh Kumar R
Email address:      suresh.arsenal29@gmail.com
PostgreSQL version: 10.3
Operating system:   Ubuntu 16.04
Description:        

I have a table 'person' with properties _id, _actual_type_name and name when
I tried the below query, I got an error saying 'could not find pathkey item
to sort'.

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 );

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.