Re: BUG #15352: postgresql FDW error "ERROR: ORDER BY position 0 is not in select list" - Mailing list pgsql-bugs

From Andrew Gierth
Subject Re: BUG #15352: postgresql FDW error "ERROR: ORDER BY position 0 is not in select list"
Date
Msg-id 87pnxyx6kf.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to Re: BUG #15352: postgresql FDW error "ERROR: ORDER BY position 0 isnot in select list"  (Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>)
List pgsql-bugs
>>>>> "Ashutosh" == Ashutosh Bapat <ashutosh.bapat@enterprisedb.com> writes:

 Ashutosh> Looking at deparseSortGroupClause() this issue looks to be
 Ashutosh> fixed in HEAD. Either the version where bug was found doesn't
 Ashutosh> have this fix or somehow the fix isn't working.

You're misreading the code. The OP's example clearly demonstrates the
bug when tested with HEAD prior to bf2d0462c or with bf2d0462c reverted.

As the code stands, it _cannot_ use deparseSortGroupClause for
generating EXPLAINs for pathkeys that are chosen by postgres_fdw,
because deparseSortGroupClause wants a tlist, not a plain list of
expressions.

(Perhaps you haven't realized that without the additional check, when
remote estimates are enabled we end up sending EXPLAIN commands to the
remote for paths that cannot possibly be of any use in the query?
Round-trips to the remote are not free.)

 >> How do you think that could happen, given that redundant pathkeys
 >> are already removed?

 Ashutosh> I don't have exact answer.

Then you should find out.

 Ashutosh> But deparseSortGroupClause() has code to deparse constants in
 Ashutosh> GROUP BY indicates that we do encounter such pathkeys
 Ashutosh> somewhere.

GROUP BY isn't based on pathkeys (for one thing, grouping columns might
not be sortable).

 Ashutosh> I am thinking about ORDER BY being pushed down for GROUP BY.

Perhaps you should take a look at how the pathkeys for that case are
generated.

-- 
Andrew (irc:RhodiumToad)


pgsql-bugs by date:

Previous
From: "Melek JARRAYA"
Date:
Subject: Re: Not found indexed word
Next
From: jhm713
Date:
Subject: Re: Inconsistencies restoring public schema ownership from pg_dump