Re: Faster distinct query?

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Michael Lewis <mlewis(at)entrata(dot)com>
Cc: Israel Brewster <ijbrewster(at)alaska(dot)edu>, PostgreSQL Mailing Lists <pgsql-general(at)postgresql(dot)org>
Subject: Re: Faster distinct query?
Date: 2021-09-23 00:58:31
Message-ID: CAApHDvoWkyQxTq=aS20A_879+micPenOnPA1RWbK8kAuCe8+mA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 23 Sept 2021 at 08:21, Michael Lewis <mlewis(at)entrata(dot)com> wrote:
> select station, array_agg(distinct(channel)) as channels
> FROM(
> SELECT station,channel FROM data GROUP BY station,channel
> ) AS sub
> group by station;

Since the subquery is grouping by station, channel, then there's no
need for the DISTINCT in the aggregate function. Removing that should
remove some tuplestore overhead from the aggregate node.

David

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Rowley 2021-09-23 01:10:38 Re: Faster distinct query?
Previous Message Tom Lane 2021-09-22 23:48:39 Re: Faster distinct query?