Re: Unique index prohibits partial aggregates

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: "Bos, Fred" <fbos(at)huisman-nl(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Unique index prohibits partial aggregates
Date: 2022-06-28 18:24:56
Message-ID: CAApHDvpuPHGBzngQY7qy4KeAAjP=OECVxq79dzA9ked7GBm3cw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 29 Jun 2022 at 00:45, Bos, Fred <fbos(at)huisman-nl(dot)com> wrote:
> Finally, is there a way to force postgres to do the partial hash aggregate,
> either by changing a setting or by influencing the expected amount of output
> groups for each query?

You could do something like:

ALTER TABLE bhload_nohyp_noin ALTER COLUMN t SET (n_distinct = 200);
ANALYZE bhload_nohyp_noin;

Please be aware that this may have detrimental effects if you do any
joins or group bys directly on this column. Otherwise, providing you
don't have a unique index on that column, then it should trick the
planner into thinking there will be fewer groups than it currently
thinks there will be, which will likely result in the parallel plan
that you desire.

David

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bryn Llewellyn 2022-06-29 01:41:58 User's responsibility when using a chain of "immutable" functions?
Previous Message vignesh C 2022-06-28 16:47:31 Re: Support logical replication of DDLs