Re: Significant performance issues with array_agg() + HashAggregate plans on Postgres 17

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Scott Carey <scott(dot)carey(at)algonomy(dot)com>, pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Significant performance issues with array_agg() + HashAggregate plans on Postgres 17
Date: 2026-04-07 21:58:22
Message-ID: af12804ead9f0530c3946c849099c5ef35763527.camel@j-davis.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Richard Guo 2026-04-09 08:05:11 Re: Potential partition pruning regression on PostgreSQL 18
Previous Message Richard Guo 2026-04-07 08:00:17 Re: Potential partition pruning regression on PostgreSQL 18