pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rod Taylor <pg@rbt.ca>
To: Vitaly Belman <vitalib@012.net.il>
Cc: Postgresql Performance <pgsql-performance@postgresql.org>
Subject: Re: Simply join in PostrgeSQL takes too long
Date: Tue, 27 Apr 2004 18:01:34 -0400
Message-ID: <1083103293.30065.100.camel@jester> (raw)
In-Reply-To: <282909734.20040428002740@012.net.il>
References: <282909734.20040428002740@012.net.il>

On Tue, 2004-04-27 at 17:27, Vitaly Belman wrote:
> Hello pgsql-performance,
> 
>   I discussed the whole subject for some time in DevShed and didn't
>   achieve much (as for results). I wonder if any of you guys can help
>   out:
> 
>   http://forums.devshed.com/t136202/s.html

You're taking the wrong approach. Rather than using a select query to
ensure that the book_id is distinct, add a constraint to the table so
that is guaranteed.

        CREATE UNIQUE INDEX bv_bookgeneres_unq ON bv_bookgenres(book_id,
        genre_id);
        
Now you can do a simple join (Drop the DISTINCT keyword) and achieve the
same results.

The point is that a book cannot be of a certain genre more than once.

Without the distinct, this should take a matter of a few milliseconds to
execute.





view thread (12+ messages)  latest in thread

Message-ID: <1083103293.30065.100.camel@jester>
Permalink:  ../1083103293.30065.100.camel@jester/
Also on:    postgresql.org/message-id/1083103293.30065.100.camel@jester

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: pg@rbt.ca, vitalib@012.net.il
  Subject: Re: Simply join in PostrgeSQL takes too long
  In-Reply-To: <1083103293.30065.100.camel@jester>

* 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