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 1wAERK-002Bfz-1c for pgsql-performance@arkaria.postgresql.org; Tue, 07 Apr 2026 21:58:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wAERI-002hzH-2y for pgsql-performance@arkaria.postgresql.org; Tue, 07 Apr 2026 21:58:29 +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 1wAERI-002hz9-1c for pgsql-performance@lists.postgresql.org; Tue, 07 Apr 2026 21:58:29 +0000 Received: from mail-dy1-x1330.google.com ([2607:f8b0:4864:20::1330]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wAERG-00000001BfG-060H for pgsql-performance@lists.postgresql.org; Tue, 07 Apr 2026 21:58:28 +0000 Received: by mail-dy1-x1330.google.com with SMTP id 5a478bee46e88-2ba9c484e5eso5443502eec.1 for ; Tue, 07 Apr 2026 14:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20251104.gappssmtp.com; s=20251104; t=1775599104; x=1776203904; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=2PBsi96JoJvNr549+QiBUcuxAflhhnXtKeqNuynysnM=; b=fVkHEUkUQJLyOtLGP3wpA92JSxDZUe09Bw6CYEh6+ATsBXNRl9cIlPY3vwtn3wngyq U67hxbvyaeXZQtPq+lIc40q0hLaG+YE07exRYlm27tmDp0c3FnY5b4gQuehkZIAchWJ1 tSoJ5YwS0brtV1/7ht8r5mL5Uz+3OxgtMs1erspKuwEAmVyB9e7fo9KMhyXjXSFE6wgl DQ9azHc2rlltckakx0z7rN+dd7cRRHitXqB1ZjgdYQNpIN4GvRI1CCgGSEoOuzgR33ZC ba57Mf4zp4FY2WyL0CPAAqdli4YRYadwO1kfPB4XnsVdciRWdXKUhLwGTN+mPhdjrVFL 8hOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775599104; x=1776203904; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2PBsi96JoJvNr549+QiBUcuxAflhhnXtKeqNuynysnM=; b=bUPyah5BpNR5Dz09O1McsPSX6SsGub0AVRIdBCncTZ5VpldEuDkS1fYn42dD0qaflD aVywyT84zmofFaEF9jb8RMYx2Fxi4MzyuF3gag0NY9mVOtjDIjbo+8xka2jdB3mX/eKt 3+7BaUwwAX1bV3TqvLJmRTnC9MKQdps/qVSx4hPTLZyZ4oZhezoFo0G3roj1NhH2xDBQ +6ogdgZyDvwLOSOvKouSOl3Mg71cvv4CI/qtMd695nGTnyOlnPwzNWd6DXMMhLpLrb70 Mj6XgR2sDG12Boq5d5EN8CDWRwFarQAKrpYJFzd0j9K1gJ87ySEARSMwGWBwPhe7yz27 4xsg== X-Forwarded-Encrypted: i=1; AJvYcCXfwxMt3IiFBuDWjL5gRVsdE6fZvsvMqzeL//6jktRYDq5sjLPDWL3ZAISY78R/k57d6zRCukFUkB0cXBwnmlI+xQ==@lists.postgresql.org X-Gm-Message-State: AOJu0YzsZo8+lg/cj6DGkvmSouMubXsOlse5XHsUOWSlGvPkSTzttMVO VxTcNQkmksIBgOA2YCBVV+l7p3/BDvKUZRt5FB4obUmK3Q/xtGmp5ouJD76u0zBNhA== X-Gm-Gg: AeBDieu6jNRzKuFFrPnRi/Ut5u+PsjeZjCDA/Mnup/HeqHu1vArdSrsLd1hoOi0acdd 72rIGCuRptryWlNp3ZrXk3JjHRTziL4UStYFmW+xF5QYIQ3YMdzm+6hEtTpFHZIr4raimNM0x+R 0aHE1xj/F/tFWvaaWi8HNI6pLe5oxLJucwdjBsdiT50ZEZvLtPTVD/PixKJ40EIG1TPeGtBnvZJ hifyQFtN9pX52UknzzgXD5WqeRMuL6iAWAHOvAYLy06k01otlOGVBDVlSDxYdXqEPQ7Fe5odNzj 2xJsIMutwdE9l9u/sRkGNxtusHSEqL3tLJBXzoZtzu5RoljonupM9uYZExIxtd+vMcY0ukeTDU7 dhLEdnOp+Csd7AQkRsXfOhGyiz9HwODsAwYg9nkYhGk8vxXCytHBWrlyPe9bFBBm1LRq9tVyCI4 ABX6PxtwJnST3G7z7vjr0= X-Received: by 2002:a05:7300:e108:b0:2c9:ee15:a0d6 with SMTP id 5a478bee46e88-2cbfc363928mr9796417eec.29.1775599103971; Tue, 07 Apr 2026 14:58:23 -0700 (PDT) Received: from [10.15.243.33] ([12.3.62.122]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2cf2be19f85sm12121726eec.30.2026.04.07.14.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2026 14:58:23 -0700 (PDT) Message-ID: Subject: Re: Significant performance issues with array_agg() + HashAggregate plans on Postgres 17 From: Jeff Davis To: David Rowley , Tom Lane Cc: Scott Carey , pgsql-performance@lists.postgresql.org Date: Tue, 07 Apr 2026 14:58:22 -0700 In-Reply-To: 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> <3829071.1775246182@sss.pgh.pa.us> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.3-0ubuntu1.1 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, 2026-04-04 at 13:21 +1300, David Rowley wrote: > A slight variation on this that I was thinking of would be to > introduce a MemoryPool struct that could be tagged onto a > MemoryContext which contains a pool_limit. A child MemoryContext > would, by default, inherit its parent's MemoryPool. On malloc/free, > if > the owning context has a non-null MemoryPool, the MemoryPool's > memory_allocated is updated. At a safe point in nodeAgg.c, we'd check > if the pool limit has been reached. I assume there's some simple > inline function that just checks if memory_allocated is greater than > pool_limit. Doing it this way would mean there's no need to > recursively propagate the mentioned child_mem_allocated field up the > hierarchy, as there is only a single field to update if the > MemoryPool > field is set. I like that idea, because it could also be a good place to hold a max block size for that tree of contexts. That's important to ensure that the block size is significantly less than work_mem. But it also means there's only one pool in any given subtree (unless you mean that we should make that work somehow), which is an awkward requirement, especially with MemoryContextSetParent(). Regards, Jeff Davis