pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #18381: Invalid query generated by postgres_fdw with UNION ALL and ORDER BY
2+ messages / 2 participants
[nested] [flat]

* BUG #18381: Invalid query generated by postgres_fdw with UNION ALL and ORDER BY
@ 2024-03-07 10:22 PG Bug reporting form <noreply@postgresql.org>
  2024-03-07 11:32 ` Re: BUG #18381: Invalid query generated by postgres_fdw with UNION ALL and ORDER BY David Rowley <dgrowleyml@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2024-03-07 10:22 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: michal@kleczek.org

The following bug has been logged on the website:

Bug reference:      18381
Logged by:          Michal Kleczek
Email address:      michal@kleczek.org
PostgreSQL version: 16.2
Operating system:   Linux
Description:        

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.

[1]
https://www.postgresql.org/message-id/B2AC13F9-6655-4E27-BFD3-068844E5DC91%40kleczek.org



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #18381: Invalid query generated by postgres_fdw with UNION ALL and ORDER BY
  2024-03-07 10:22 BUG #18381: Invalid query generated by postgres_fdw with UNION ALL and ORDER BY PG Bug reporting form <noreply@postgresql.org>
@ 2024-03-07 11:32 ` David Rowley <dgrowleyml@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: David Rowley @ 2024-03-07 11:32 UTC (permalink / raw)
  To: michal@kleczek.org; pgsql-bugs@lists.postgresql.org

On Thu, 7 Mar 2024 at 23:35, PG Bug reporting form
<noreply@postgresql.org> wrote:
>
> The following bug has been logged on the website:
>
> Bug reference:      18381
> Logged by:          Michal Kleczek
> Email address:      michal@kleczek.org
> PostgreSQL version: 16.2
> Operating system:   Linux
> Description:

I see you've raised this on -hackers [1] already.   Since there's
already some discussion and a proposed fix there, I think it's better
the discussion continues there.

David

[1] https://postgr.es/m/0714C8B8-8D82-4ABB-9F8D-A0C3657E7B6E@kleczek.org





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-03-07 11:32 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-03-07 10:22 BUG #18381: Invalid query generated by postgres_fdw with UNION ALL and ORDER BY PG Bug reporting form <noreply@postgresql.org>
2024-03-07 11:32 ` David Rowley <dgrowleyml@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox