pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Michał Kłeczek <michal@kleczek.org>
To: PG-General Mailing List <pgsql-general@postgresql.org>
Subject: Re: postgres_fdw aggregate pushdown for group by with expressions
Date: Sun, 3 Mar 2024 08:19:10 -0800
Message-ID: <2b5c8483-ff9b-4fb2-8ed8-2e77e0f1f936@aklaver.com> (raw)
In-Reply-To: <5FC17CB3-3048-455D-B638-B48949F78D06@kleczek.org>
References: <AF30BDFB-7215-4E8C-BF11-C97573199D6C@kleczek.org>
	<5FC17CB3-3048-455D-B638-B48949F78D06@kleczek.org>

On 3/3/24 05:16, Michał Kłeczek wrote:
> 
> 
>> On 3 Mar 2024, at 10:34, Michał Kłeczek <michal@kleczek.org> wrote:
>>
>> Hi,
>>
>> I have the following foreign table:
>>
>> CREATE FOREIGN TABLE t1 (
>>   grouping_column text,
>>   date_column date,
>>   whatever_data int
>> );
>>
>> The query is:
>>
>> SELECT
>>   sum(whatever_data)
>> FROM
>>   t1
>> GROUP BY
>>   grouping_colulmn, extract(YEAR FROM date_column), extract(MONTH FROM date_column);
>>
>>  From my (preliminary) testing postgres_fdw will not push down this aggregate query
>> - it will happily push down query with only “grouping_column” or “grouping_column, date_column" in GROUP BY
>>
>> Is there a way to somehow push down the query with expressions in GROUP BY?
> 
> I’ve performed some more tests and it seems expressions with “extract” function are not pushed down at all -
> the WHERE criteria from the following query are not pushed down as well and filter is performed locally:
> 
> SELECT
>    *
> FROM
>    t1
> WHERE extract(YEAR FROM date_column) = 2023
> 
> I was under impression that “extract” meets all criteria for pushable expressions - looks like I am wrong?
> 
> What would be the expression to achieve the same but such that postgres_fdw would push it down?

What Postgres versions on both ends?

What does

select proname, prosrc,  provolatile from pg_proc where proname = 'extract';

return?

> 
> Thanks,
> Michal
> 
> 
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com






view thread (10+ messages)  latest in thread

Message-ID: <2b5c8483-ff9b-4fb2-8ed8-2e77e0f1f936@aklaver.com>
Permalink:  ../2b5c8483-ff9b-4fb2-8ed8-2e77e0f1f936@aklaver.com/
Also on:    postgresql.org/message-id/2b5c8483-ff9b-4fb2-8ed8-2e77e0f1f936@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, michal@kleczek.org
  Subject: Re: postgres_fdw aggregate pushdown for group by with expressions
  In-Reply-To: <2b5c8483-ff9b-4fb2-8ed8-2e77e0f1f936@aklaver.com>
  References: <AF30BDFB-7215-4E8C-BF11-C97573199D6C@kleczek.org> <5FC17CB3-3048-455D-B638-B48949F78D06@kleczek.org> <2b5c8483-ff9b-4fb2-8ed8-2e77e0f1f936@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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