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

Scott Carey <scott.carey@algonomy.com>

From: Scott Carey <scott.carey@algonomy.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: pgsql-performance@lists.postgresql.org
Date: 2026-03-31T18:06:36Z
Lists: pgsql-performance
On Tue, Mar 31, 2026 at 10:55 AM Scott Carey <scott.carey@algonomy.com>
wrote:

>
> On Tue, Mar 31, 2026 at 5:03 AM David Rowley <dgrowleyml@gmail.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
>>
>

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Disk-based Hash Aggregation.