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 1mxGdu-0002Bz-Se for pgsql-general@arkaria.postgresql.org; Tue, 14 Dec 2021 22:51:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mxGds-0008CE-EA for pgsql-general@arkaria.postgresql.org; Tue, 14 Dec 2021 22:51:28 +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 1mxGds-0008C5-3k for pgsql-general@lists.postgresql.org; Tue, 14 Dec 2021 22:51:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mxGdk-00072Y-LR for pgsql-general@lists.postgresql.org; Tue, 14 Dec 2021 22:51:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1BEMpIgl559032; Tue, 14 Dec 2021 17:51:19 -0500 From: Tom Lane To: Matt Magoffin cc: pgsql-general@lists.postgresql.org Subject: Re: Properly handling aggregate in nested function call In-reply-to: <0005FD8A-0FBE-4D53-BBDE-7242A4DC525C@msqr.us> References: <0005FD8A-0FBE-4D53-BBDE-7242A4DC525C@msqr.us> Comments: In-reply-to Matt Magoffin message dated "Tue, 14 Dec 2021 10:12:31 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <559030.1639522278.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 14 Dec 2021 17:51:18 -0500 Message-ID: <559031.1639522278@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Matt Magoffin writes: > Any ideas what I=E2=80=99m doing wrong here? The source is available her= e: > https://github.com/SolarNetwork/aggs_for_vecs/blob/9e742cdc32a113268fd3c= 1f928c8ac724acec9f5/vec_agg_mean.c Hmm, I think you're abusing the ArrayBuildState API. In particular, what guarantees that the astate->dvalues and astate->dnulls arrays are long enough for what you're stuffing into them? You should probably palloc temp arrays right here and then use construct_md_array directly instead of dealing with an ArrayBuildState. Also, I wonder what happens when state->vec_counts[i] is zero. That's seemingly not your problem right now, since the ereport(NOTICE) is being reached; but it sure looks like trouble waiting to happen. regards, tom lane