Re: master-detail relationship and count

From: "Dan Langille" <dan(at)langille(dot)org>
To: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: master-detail relationship and count
Date: 2002-11-29 14:24:37
Message-ID: 3DE73255.29778.E71B8DFA@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 29 Nov 2002 at 13:16, Achilleus Mantzios wrote:

> On Fri, 29 Nov 2002, Gary Stainburn wrote:
>
> > As you can see from the extract below, your statement has worked for all
> > landmarks that have links, but ignores any landmarks with out links. How can
> > I adjust this so that all landmarks are listed, but with a zero count where
> > appropriate?
>
> Then, use LEFT OUTER JOIN ... USING (),
> in combination with COALESCE().
>
> (read the docs)

When it comes to outer joins, this page is quite useful:

http://www.postgresql.org/idocs/index.php?explicit-joins.html

I was reading it yesterday when improving the speed of some JOINs.
The JOIN went from 3440ms to about 18ms when following the advice on
that page.

I've put the queries and the explain output at
http://www.freshports.org/tmp/outer-join.txt. This will be an
example of an OUTER JOIN but not the master-detail situation which
occurs elsewhere in the database.

cheers

--
Dan Langille : http://www.langille.org/

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2002-11-29 14:39:50 Re: master-detail relationship and count
Previous Message Rafal Kedziorski 2002-11-29 12:13:50 import sql script