Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mheuA-0000ZF-Mq for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Nov 2021 21:31:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mheu8-0000qP-EW for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Nov 2021 21:31:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mheu8-0000oJ-1J for pgsql-hackers@lists.postgresql.org; Mon, 01 Nov 2021 21:31:44 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mheu1-0006xG-Ag for pgsql-hackers@postgresql.org; Mon, 01 Nov 2021 21:31:43 +0000 Received: from [192.168.0.168] (broadband-188-32-162-150.ip.moscow.rt.ru [188.32.162.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id AEDF121C1B2B; Tue, 2 Nov 2021 00:31:35 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1635802295; bh=THLDG8YU1Osm+0TKPKO827EYSrugYwCQJ0AmasgMpIg=; h=Subject:To:References:From:Cc:Date:In-Reply-To; b=newGy6gdRLCcPCV9cnWvQcs9thi2FgmIUNDHWQkMoMt5toH/uX4g7u2p5p+c3uKa4 I2FbNpa68zVcEdZMpdphx66bEJEaqLoNWybda+NqDqFmkdLjFUB9mdrOlbmQ0Jis7q U5OBjPjvfntxdGtsutk0T6OvixiLJ0EIFx9HZsq4= Subject: Re: Partial aggregates pushdown To: Alexander Pyhalov References: <2486a6db3f068efb97c1277c23402e0d@postgrespro.ru> <504e576d-984f-d73c-2694-8ee9624f8def@enterprisedb.com> <07fa4d5a56f402732acfce25e7207cae@postgrespro.ru> From: Ilya Gladyshev Cc: pgsql-hackers@postgresql.org Message-ID: <0fbeb9d7-0a8f-8e2c-0687-2d4c32c66a9c@postgrespro.ru> Date: Tue, 2 Nov 2021 00:31:35 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <07fa4d5a56f402732acfce25e7207cae@postgrespro.ru> Content-Type: multipart/alternative; boundary="------------178E80676017AB4326D0E3E9" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------178E80676017AB4326D0E3E9 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi, On 21.10.2021 13:55, Alexander Pyhalov wrote: > Hi. Updated patch. > Now aggregates with internal states can be pushed down, if they are > marked as pushdown safe (this flag is set to true for min/max/sum), > have internal states and associated converters. I don't quite understand why this is restricted only to aggregates that have 'internal' state, I feel like that should be possible for any aggregate that has a function to convert its final result back to aggregate state to be pushed down. While I couldn't come up with a useful example for this, except maybe for an aggregate whose aggfinalfn is used purely for cosmetic purposes (e.g. format the result into a string), I still feel that it is an unnecessary restriction. A few minor review notes to the patch: +static List *build_conv_list(RelOptInfo *foreignrel); this should probably be up top among other declarations. @@ -1433,6 +1453,48 @@ postgresGetForeignPlan(PlannerInfo *root,                              outer_plan);  } +/* + * Generate attinmeta if there are some converters: + * they are expecxted to return BYTEA, but real input type is likely different. + */ typo in word "expec*x*ted". @@ -139,10 +147,13 @@ typedef struct PgFdwScanState                                   * for a foreign join scan. */      TupleDesc    tupdesc;        /* tuple descriptor of scan */      AttInMetadata *attinmeta;    /* attribute datatype conversion metadata */ +    AttInMetadata *rcvd_attinmeta;    /* metadata for received tuples, NULL if +                                     * there's no converters */ Looks like rcvd_attinmeta is redundant and you could use attinmeta for conversion metadata. The last thing - the patch needs to be rebased, it doesn't apply cleanly on top of current master. Thanks, Ilya Gladyshev --------------178E80676017AB4326D0E3E9 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hi,

On 21.10.2021 13:55, Alexander Pyhalov wrote:
Hi. Updated patch.
Now aggregates with internal states can be pushed down, if they are marked as pushdown safe (this flag is set to true for min/max/sum),
have internal states and associated converters.

I don't quite understand why this is restricted only to aggregates that have 'internal' state, I feel like that should be possible for any aggregate that has a function to convert its final result back to aggregate state to be pushed down. While I couldn't come up with a useful example for this, except maybe for an aggregate whose aggfinalfn is used purely for cosmetic purposes (e.g. format the result into a string), I still feel that it is an unnecessary restriction.

A few minor review notes to the patch:


+static List *build_conv_list(RelOptInfo *foreignrel);

this should probably be up top among other declarations.


@@ -1433,6 +1453,48 @@ postgresGetForeignPlan(PlannerInfo *root,
                             outer_plan);
 }
 
+/*
+ * Generate attinmeta if there are some converters:
+ * they are expecxted to return BYTEA, but real input type is likely different.
+ */


typo in word "expecxted".


@@ -139,10 +147,13 @@ typedef struct PgFdwScanState
                                  * for a foreign join scan. */
     TupleDesc    tupdesc;        /* tuple descriptor of scan */
     AttInMetadata *attinmeta;    /* attribute datatype conversion metadata */
+    AttInMetadata *rcvd_attinmeta;    /* metadata for received tuples, NULL if
+                                     * there's no converters */


Looks like rcvd_attinmeta is redundant and you could use attinmeta for conversion metadata.

The last thing - the patch needs to be rebased, it doesn't apply cleanly on top of current master.

Thanks,

Ilya Gladyshev


--------------178E80676017AB4326D0E3E9--