Re: Slow Count-Distinct Query - Mailing list pgsql-performance

From bricklen
Subject Re: Slow Count-Distinct Query
Date
Msg-id CAGrpgQ9ga0N0cF8+Z0ZW8t1mgS=3v1igVdaiciz-Q5Z7ddfOyA@mail.gmail.com
Whole thread Raw
In response to Slow Count-Distinct Query  (Christopher Jackson <crjackso@gmail.com>)
Responses Re: Slow Count-Distinct Query
List pgsql-performance

On Sun, Mar 30, 2014 at 12:45 PM, Christopher Jackson <crjackso@gmail.com> wrote:
  Hi all,

  tl;dr - How can I speed up my count-distinct query?  

Depending on how often you need to run that query and how important it is to you, if you are willing to accept a performance hit on INSERT/UPDATE/DELETE of the "participants" table, you could create a summary table containing just the count of unique email addresses or the list of unique email addresses populated via trigger on INSERT/UPDATE/DELETE of the  participants table. Another option is try out the new Materialized views (http://www.postgresql.org/docs/current/static/sql-creatematerializedview.html) available in 9.3.

pgsql-performance by date:

Previous
From: Andres Freund
Date:
Subject: Re: Sudden crazy high CPU usage
Next
From: Christopher Jackson
Date:
Subject: Re: Slow Count-Distinct Query