pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mladen Gogala <gogala.mladen@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Faster distinct query?
Date: Wed, 22 Sep 2021 23:02:12 -0400
Message-ID: <135cb451-c8d0-28ed-f563-0bd3bf2f2438@gmail.com> (raw)
In-Reply-To: <CAKFQuwYJbD2Xy+jNx30zdLmm7Xk6ZcP1_2N_hJqyqAcoYfB8SQ@mail.gmail.com>
References: <0BB059BF-54BD-46FA-8B26-28FEF9A04198@alaska.edu>
	<CAKFQuwYJbD2Xy+jNx30zdLmm7Xk6ZcP1_2N_hJqyqAcoYfB8SQ@mail.gmail.com>


On 9/22/21 16:20, David G. Johnston wrote:
> I'd probably turn that index into a foreign key that just ensures that 
> every (station,channel) that appears in the data table also appears on 
> the lookup table.  Grouping and array-ifying the lookup table would be 
> trivial.  Either modify the application code or add a trigger to 
> populate the lookup table as needed.


I fully agree with this. Adding a trigger to populate a lookup table is 
a standard design in situations like this. Using "DISTINCT" almost 
always spells trouble for the performance.


-- 
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com






view thread (34+ messages)  latest in thread

Message-ID: <135cb451-c8d0-28ed-f563-0bd3bf2f2438@gmail.com>
Permalink:  ../135cb451-c8d0-28ed-f563-0bd3bf2f2438@gmail.com/
Also on:    postgresql.org/message-id/135cb451-c8d0-28ed-f563-0bd3bf2f2438@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: gogala.mladen@gmail.com
  Subject: Re: Faster distinct query?
  In-Reply-To: <135cb451-c8d0-28ed-f563-0bd3bf2f2438@gmail.com>
  References: <0BB059BF-54BD-46FA-8B26-28FEF9A04198@alaska.edu> <CAKFQuwYJbD2Xy+jNx30zdLmm7Xk6ZcP1_2N_hJqyqAcoYfB8SQ@mail.gmail.com> <135cb451-c8d0-28ed-f563-0bd3bf2f2438@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox