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

From: Scott Carey <scott(dot)carey(at)algonomy(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Significant performance issues with array_agg() + HashAggregate plans on Postgres 17
Date: 2026-03-31 18:06:36
Message-ID: CA+vubOHgrdkm+3wgC0FPcStDeMS9ZQ_Du9vUXWjxN9MN9CO2uw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Tue, Mar 31, 2026 at 10:55 AM Scott Carey <scott(dot)carey(at)algonomy(dot)com>
wrote:

>
> On Tue, Mar 31, 2026 at 5:03 AM David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
>
>>
>> I tried and failed to recreate this locally on 17.9. For me the
>> json_agg query is slower than array_agg(). I tried making the table
>> 10x bigger and still don't see the same issue. The one with more
>> work_mem and fewer batches is always faster for me.
>
>
> I don't know what other differences there could be, other than OS. This
> reproduces for me on Linux with the above on a RHEL 9 clone (pg 17) or with
> Ubuntu 25.10 (pg 16) so I suspect it is not too picky about the distro used.
>
> -Scott
>

I thought of two other possible differences: extensions and JIT:

List of installed extensions
Name | Version | Default version | Schema |
Description
--------------------+---------+-----------------+------------+-----------------------------------------------------------
pg_stat_statements | 1.11 | 1.11 | public | track
execution statistics of all SQL statements executed
plpgsql | 1.0 | 1.0 | pg_catalog | PL/pgSQL
procedural language
vector | 0.8.2 | 0.8.2 | public | vector data
type and ivfflat and hnsw access methods

show jit;
jit
-----
on

select pg_jit_available();
pg_jit_available
------------------
t

>
>
>>
>> David
>>
>

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2026-03-31 19:26:09 Re: Significant performance issues with array_agg() + HashAggregate plans on Postgres 17
Previous Message Scott Carey 2026-03-31 17:55:42 Re: Significant performance issues with array_agg() + HashAggregate plans on Postgres 17