Invalid query generated by postgres_fdw with UNION ALL and ORDER BY

Поиск
Список
Период
Сортировка
От Michał Kłeczek
Тема Invalid query generated by postgres_fdw with UNION ALL and ORDER BY
Дата
Msg-id 0714C8B8-8D82-4ABB-9F8D-A0C3657E7B6E@kleczek.org
обсуждение исходный текст
Ответы Re: Invalid query generated by postgres_fdw with UNION ALL and ORDER BY  (David Rowley <dgrowleyml@gmail.com>)
Список pgsql-hackers
The following query:

SELECT * FROM (
  SELECT 2023 AS year, * FROM remote_table_1
  UNION ALL
  SELECT 2022 AS year, * FROM remote_table_2
)
ORDER BY year DESC;

yields the following remote query:

SELECT [columns] FROM remote_table_1 ORDER BY 2023 DESC

and subsequently fails remote execution.


Not really sure where the problem is - the planner or postgres_fdw.
I guess it is postgres_fdw not filtering out ordering keys.

This filtering would also be pretty useful in the following scenario (which is also why I went through UNION ALL route and discovered this issue):

I have a table partitioned by year, partitions are remote tables.
On remote servers I have a GIST index that does not support ordering ([1]) so I would like to avoid sending ORDER BY year to remote servers.
Ideally redundant ordering should be filtered out.



Kind regards,
Michal

В списке pgsql-hackers по дате отправления:

Предыдущее
От: shveta malik
Дата:
Сообщение: Re: Missing LWLock protection in pgstat_reset_replslot()
Следующее
От: John Naylor
Дата:
Сообщение: Re: [PoC] Improve dead tuple storage for lazy vacuum