Fix incorrect Assert in add_foreign_ordered_paths

12933dc60 (originally 66c0185a3) added setop_pathkeys for providing
presorted inputs for set operation from child queries when that query
doesn't have any other pathkey requirements.

add_foreign_ordered_paths() assumed that if the query had an ORDER BY
that the query_pathkeys would be equal to sort_pathkeys.  That's not
true when query_pathkeys is set to setop_pathkeys, which can happen
for set-op child queries with an ORDER BY when all the sort_pathkeys are
redundant pathkeys. (See standard_qp_callback()).

Here we relax the Assert to allow for sort_pathkeys to be empty.  In
this case it is technically ok to mark pushdown_safe as true so that
postgresGetForeignUpperPaths() allows add_foreign_final_paths() to
generate paths with the LIMIT clause pushed down.  We don't adjust that
here as that could cause plan changes in the backbranches.  Let's just
fix things enough so the Assert doesn't fail and do a proper fix in
master.

Backpatch to 17 where the setop_pathkeys field was added.

Reported-by: Robins Tharakan <[email protected]>
Author: David Rowley <[email protected]>
Reviewed-by: Robins Tharakan <[email protected]>
Discussion: 
https://postgr.es/m/caep4nawnsefmi4w+89xbhq0f-0oixcyujo9kvcbxsyl8l4r...@mail.gmail.com
Backpatch-through: 17

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/4b1abd678223ab22e1fe245547bf5b4a91db56ee

Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out | 26 ++++++++++++++++++++++++++
contrib/postgres_fdw/postgres_fdw.c            | 16 ++++++++--------
contrib/postgres_fdw/sql/postgres_fdw.sql      |  9 +++++++++
3 files changed, 43 insertions(+), 8 deletions(-)

Reply via email to