Re: Slow views - Mailing list pgsql-bugs

From Stephan Szabo
Subject Re: Slow views
Date
Msg-id 20040716222210.D97991@megazone.bigpanda.com
Whole thread Raw
In response to Slow views  (davidn-postgres@rebel.net.au)
List pgsql-bugs
On Sat, 17 Jul 2004, David Newall wrote:

> On Sat, 2004-07-17 at 13:34, Tom Lane wrote:
> > I suspect the real issue is that the implied join order is not the same.
>
> With respect, the real issue is that using the view takes 100 times
> longer than not using it.
>
> > The view-based query is really
> >
> >     a LEFT JOIN (b LEFT JOIN c LEFT JOIN d LEFT JOIN e)
> >
> > while the allegedly equivalent hand expansion is
> >
> >     a LEFT JOIN b LEFT JOIN c LEFT JOIN d LEFT JOIN e
>
> Reversing the two terms, ie view right join table, gives the same (slow)
> result.  Adding a sub-select to the expansion, as Stephan said, gives

I think you're still fundamentally misunderstanding that the two queries
above are not always the same.  The reason you got better results from
your version is that a left join b was faster, however, if the join
conditions in your view were more complicated, your version would give the
wrong results. Unless/until we know for certain under what conditions we
can reorder the joins, we can't do so without causing bugs in other
queries.

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: Cannot recreate DB scheme using pg_dump
Next
From: "Alexander M. Pravking"
Date:
Subject: Problems renaming referencing column