Re: - Slow Query

From: Rui Carvalho <rui(dot)hmcarvalho(at)gmail(dot)com>
To: Mike Ivanov <mikei(at)activestate(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: - Slow Query
Date: 2009-07-01 17:37:30
Message-ID: 4cb7e1b20907011037h2ff9c82ek9b19d3a34e53513b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

hum thanks a lot for the quick answer,

if is not abuse of your patience

what is the best alternative to the LEFT OUTER JOINS?

RC

On Wed, Jul 1, 2009 at 6:12 PM, Mike Ivanov <mikei(at)activestate(dot)com> wrote:

> > Merge Join (cost=111885.70..319492.88 rows=13016048 width=620)
>
> The outermost merge join has to go through 13 million rows. If you remove
> "distinct on (bien.uid)", you'll see that.
>
> > LEFT outer JOIN ville ON ville.uid = bien.ref_ville
> > LEFT outer JOIN freguesia_ville ON freguesia_ville.ref_ville =ville.uid
>
> This is not enough. You have to add this condition as well:
>
> AND bien.ref_ville = freguesia_ville.ref_ville
>
> In other words, when you link three tables by a common field, all three
> relationships should be explicitly expressed, otherwise you'll have this
> type of explosive row multiplication.
>
> Although I don't quite understand the purpose of the query, I don't think
> you need all those OUTER joins.
>
> Regards,
> Mike
>
>

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Scott Marlowe 2009-07-01 17:42:35 Re: - Slow Query
Previous Message Mike Ivanov 2009-07-01 17:12:23 Re: - Slow Query