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.96) (envelope-from ) id 1w8kd2-000qFh-2y for pgsql-performance@arkaria.postgresql.org; Fri, 03 Apr 2026 19:56:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w8kd1-00DtwP-1i for pgsql-performance@arkaria.postgresql.org; Fri, 03 Apr 2026 19:56:27 +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.96) (envelope-from ) id 1w8kd1-00DtwD-0m for pgsql-performance@lists.postgresql.org; Fri, 03 Apr 2026 19:56:27 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w8kcz-00000000QgA-145Y for pgsql-performance@lists.postgresql.org; Fri, 03 Apr 2026 19:56: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 633JuMi63829072; Fri, 3 Apr 2026 15:56:22 -0400 From: Tom Lane To: Jeff Davis cc: Scott Carey , David Rowley , pgsql-performance@lists.postgresql.org Subject: Re: Significant performance issues with array_agg() + HashAggregate plans on Postgres 17 In-reply-to: <3b569609adc36db30aacbf05e487b472fa8edc84.camel@j-davis.com> References: <2764544.1774985169@sss.pgh.pa.us> <2897039.1775051081@sss.pgh.pa.us> <3579239.1775151498@sss.pgh.pa.us> <3671092.1775167393@sss.pgh.pa.us> <3825075.1775244255@sss.pgh.pa.us> <3b569609adc36db30aacbf05e487b472fa8edc84.camel@j-davis.com> Comments: In-reply-to Jeff Davis message dated "Fri, 03 Apr 2026 12:36:23 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3829070.1775246182.1@sss.pgh.pa.us> Date: Fri, 03 Apr 2026 15:56:22 -0400 Message-ID: <3829071.1775246182@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jeff Davis writes: > One idea would be to update parent contexts' memory totals recursively > each time a subcontext allocates a new block. Block allocations are > infrequent enough that may be acceptable. > If we are worried about affecting unrelated cases, we could set an > "accounting_enabled" flag for the contexts we care about, which would > be automatically inherited by subcontexts, and then stop recursing up > when that flag is false. Yeah, I was speculating about similar ideas. Since mem_allocated is only changed after a malloc() or free() call, it probably wouldn't add too much overhead to propagate that up to parent contexts. I agree with having a flag to prevent the propagation from going up further than we actually care about, though. Would it make sense to accumulate those values in a separate field child_mem_allocated, rather than redefining what mem_allocated means? regards, tom lane