Re: Slow views

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: David Newall <davidn-postgres(at)rebel(dot)net(dot)au>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Slow views
Date: 2004-07-17 05:26:02
Message-ID: 20040716222210.D97991@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message David Newall 2004-07-17 07:37:01 Re: Slow views
Previous Message Tom Lane 2004-07-17 05:08:07 Re: Cannot recreate DB scheme using pg_dump