Re: - Slow Query - Mailing list pgsql-performance

From Mike Ivanov
Subject Re: - Slow Query
Date
Msg-id 4A4B98F7.2070202@activestate.com
Whole thread Raw
In response to - Slow Query  (Rui Carvalho <rui.hmcarvalho@gmail.com>)
Responses Re: - Slow Query  (Rui Carvalho <rui.hmcarvalho@gmail.com>)
Re: - Slow Query  (Віталій Тимчишин <tivv00@gmail.com>)
List pgsql-performance
 >  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


pgsql-performance by date:

Previous
From: justin
Date:
Subject: Re: - Slow Query
Next
From: Rui Carvalho
Date:
Subject: Re: - Slow Query