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 1shDWR-00EkND-Cz for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Aug 2024 19:31:03 +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 1shDWP-004zmW-KV for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Aug 2024 19:31:02 +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 1shDWP-004zmO-Am for pgsql-hackers@lists.postgresql.org; Thu, 22 Aug 2024 19:31:01 +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 1shDWL-000ztV-WA for pgsql-hackers@postgresql.org; Thu, 22 Aug 2024 19:31:01 +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=sPBe0gCFBpad/P8xWcsRP829vEuVUnbdYZH9x0QB8vY=; b=JC2yh fUvgIS5uwr7rQot66jNZZvI2/ET8b6CpyZDZz9dAJ5PSt0SKPh6p76OOcji8BJ9+6nix+KNSLfrP2 ZywcvjJ9lohAON9DPekRV1WUfSE4JMhTwCww2b09a3Ty83zPdYBoPNnrizJHA/8kx69QyWrtIPcqX JILvTYSWARko7gQv+n23nnHZquFhqerwL0Fipr+IKsk1qcSf+62Vmx2WOmFYtw4Rqn8vrcP+jjPzp LAnie5DylaDH96n9NGwnEtI2B690BiaWl0tgS10uH0QqXYnX+pFfiEENuLwE2F9Lo5wTwgNOpaCLG AMjwW2lFduHSOCylkP8mcWTsxqMig==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1shDWH-00GTSq-07; Thu, 22 Aug 2024 15:30:53 -0400 Date: Thu, 22 Aug 2024 15:30:53 -0400 From: Bruce Momjian To: Tomas Vondra Cc: Jelte Fennema-Nio , "Fujii.Yuki@df.MitsubishiElectric.co.jp" , PostgreSQL-development , Robert Haas , Tom Lane , Stephen Frost , Andres Freund , Tomas Vondra , Julien Rouhaud , Daniel Gustafsson , vignesh C , Alexander Pyhalov Subject: Re: Partial aggregates pushdown Message-ID: References: <91f71f11-3431-49ab-95d0-1c5c90be9fb0@vondra.me> 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 Thu, Aug 22, 2024 at 08:31:11PM +0200, Tomas Vondra wrote: > > My question is related to #3 and #4. For #3, if we are going to be > > building infrastructure to handle passing int128 for AVG, wouldn't it be > > wiser to create an int128 type and an int128 array type, and then use > > method #2 to handle those, rather than creating custom code just to > > read/write int128 values for FDWs aggregate passing alone. > > > > Yep, adding int128 as a data type would extend this to aggregates that > store state as int128 (or array of int128). Great, I am not too far off then. > > For #4, can we use or improve the RECORD data type to handle #4 --- that > > seems preferable to creating custom FDWs aggregate passing code. > > > > I know the open question was whether we should create custom FDWs > > aggregate passing functions or custom data types for FDWs aggregate > > passing, but I am asking if we can improve existing facilities, like > > int128 or record passing, to reduce the need for some of these. > > > > But which code would produce the record? AFAIK it can't happen in some > generic executor code, because that only sees "internal" for each > aggregate. The exact structure of the aggstate is private within the > code of each aggregate - the record would have to be built there, no? > > I imagine we'd add this for each aggregate as a new pair of functions to > build/parse the record, but that's kinda the serial/deserial way we > discussed earlier. > > Or are you suggesting we'd actually say: > > CREATE AGGREGATE xyz(...) ( > STYPE = record, > ... > ) So my idea from the email I just sent is to create a pg_proc.proargtypes-like column (data type oidvector) for pg_aggregate which stores the oids of the values we want to return, so AVG(interval) would have an array of the oids for interval and int8, e.g.: SELECT oid FROM pg_type WHERE typname = 'interval'; oid ------ 1186 SELECT oid FROM pg_type WHERE typname = 'int8'; oid ----- 20 SELECT '1186 20'::oidvector; oidvector ----------- 1186 20 It seems all four methods could use this, again assuming we create int128/int16 and whatever other types we need. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you.