Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sErFs-00468j-GY for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Jun 2024 14:04:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sErFs-008qiS-F8 for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Jun 2024 14:04:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sErFs-008qiK-4D for pgsql-hackers@lists.postgresql.org; Wed, 05 Jun 2024 14:04:44 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sErFl-00081r-7b for pgsql-hackers@postgresql.org; Wed, 05 Jun 2024 14:04:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2024011501; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description; bh=fg65f+tRzsMKkY6IqNMqrGbRySO3xZH1eApXeY8nIsc=; b=Iswjh 9HBgyuZo446j1lxVQPQ6MBZRLmnarTutAbCLJgkTsBrfLFq5oQ+pZ4NKTyJJrtrhW+DrcwXdU8qof Zi90Wo6qPI5aC9anfFI/Fy8YHhdp78DQteT7vrZpirkfd1GZWvdKkvwwM2Zk88XkIf9iCyeQ7hNu9 Hw/danCBW/Tr5LWeCWCFGhs4AtSRVcZ5VeVeBqL8uBzh/l3Kh8Ai7duSOGmRYPsUASiOvyzhI5ibi 9RUTxTihbGvmLIlhQoaDdBhW5SOFCi9zWtlhLA6xTB7CQe+0TkcJT+smFrDW765Hp8keyXX+hOXxo Sk3MIQgMWL4ONuwQ0Jpj2yJqxBGDg==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1sErFd-00HEgQ-2W; Wed, 05 Jun 2024 10:04:29 -0400 Date: Wed, 5 Jun 2024 10:04:29 -0400 From: Bruce Momjian To: Alexander Pyhalov Cc: "Fujii.Yuki@df.MitsubishiElectric.co.jp" , Robert Haas , PostgreSQL-development , Tom Lane , Stephen Frost , Andres Freund , Tomas Vondra , Julien Rouhaud , Daniel Gustafsson , vignesh C Subject: Re: Partial aggregates pushdown Message-ID: References: <31ab8f7b91cef6e837b3e31ea1e35a9a@postgrespro.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jun 5, 2024 at 08:19:04AM +0300, Alexander Pyhalov wrote: > > * Passes unsafe binary data from the foreign server. > > > > Can someone show me where that last item is in the patch, and why can't > > we just pass back values cast to text? > > In finalize_aggregate() when we see partial aggregate with > peragg->aggref->aggtranstype = INTERNALOID > we call aggregate's serialization function and return it as bytea. > > The issue is that this internal representation isn't guaranteed to be > compatible between servers > of different versions (or architectures?). So, likely, we instead should > have called some export function for aggregate > and later - some import function on postgres_fdw side. It doesn't matter > much, what this export function > generates - text, json or some portable binary format, > 1) export/import functions should just "understand" it, > 2) it should be a stable representation. Okay, so looking at the serialization output functions already defined, I see many zeros, which I assume means just the base data type, and eight more: SELECT DISTINCT aggserialfn from pg_aggregate WHERE aggserialfn::oid != 0; aggserialfn --------------------------- numeric_avg_serialize string_agg_serialize array_agg_array_serialize numeric_serialize int8_avg_serialize array_agg_serialize interval_avg_serialize numeric_poly_serialize I realize we need to return the sum and count for average, so that makes sense. So, we need import/export text representation for the partial aggregate mode for these eight, and call the base data type text import/export functions for the zero ones when in this mode? -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you.