Re: Problem with a view (not lazy ;) - Mailing list pgsql-general

From bombadil@wanadoo.es
Subject Re: Problem with a view (not lazy ;)
Date
Msg-id 20020207095014.GA10114@fangorn
Whole thread Raw
In response to Problem with a view (not lazy ;)  (bombadil@wanadoo.es)
List pgsql-general
El miércoles 06 de febrero, Tom Lane escribió:
> bombadil@wanadoo.es writes:
> >  In my tests with views I have found a problem that can't explain.
>
> Are those EXPLAINs really for equivalent queries?  I find it very
> suspicious that the estimated number of rows retrieved from "ta" is
> so different in the two cases.  I wonder whether you used the same
> range of "fecha" in both cases.

 I have used same query. That is sure.

> >     from técnico_aviso ta
> >         join empleado e on ta.empleado = e.cod
> >         join presupuesto p on ta.aviso = p.aviso
> >         join aviso a
> > ->            left join empresa em on a.empresa = em.cod
> >             on ta.aviso = a.número;
>
> Did you really mean to do it that way, and not as
>
>     from técnico_aviso ta
>         join empleado e on ta.empleado = e.cod
>         join presupuesto p on ta.aviso = p.aviso
>         join aviso a on ta.aviso = a.número
>         left join empresa em on a.empresa = em.cod;
>
> The way you wrote it forces the a-to-em left join to be done first,
> which means it will generate lots of join rows that probably won't
> be of any use.  I suspect you want to do the left join last not first.

 Wow!

 Changing what you propose enhances execute time greatly. Thanks for
 your idea. I need to experiment more with it.

 Greets.

                             David

pgsql-general by date:

Previous
From: Achilleus Mantzios
Date:
Subject: Solaris performance
Next
From: Marek PUBLICEWICZ
Date:
Subject: Re: PgManage (GUI Manager) Update