Re: optimization with limit and order by in a view - Mailing list pgsql-general

From elein
Subject Re: optimization with limit and order by in a view
Date
Msg-id 20040713192324.Z6381@cookie.varlena.com
Whole thread Raw
In response to Re: optimization with limit and order by in a view  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Thank you.  I already removed the order by in the view
definition which was put in against my recommendation...

But it is an interesting case.

If I understand you, a subquery with an order by cannot
be flattened.

cheers,

elein


On Tue, Jul 13, 2004 at 05:55:50PM -0400, Tom Lane wrote:
> elein <elein@varlena.com> writes:
> > Brain dead java beans want order by clauses in views
> > that they use.
>
> That's *quite* brain dead, considering that standard SQL doesn't allow
> ORDER BY in view definitions at all.  Sure you can't fix it on the
> client side?
>
> > What I found was that if I moved the order by outside
> > of the view definition, the query went from 5000-7000ms
> > down to 70-1.5ms.
>
> Yeah.  The planner can't flatten a subquery that contains ORDER BY into
> the parent query, because there'd be no place to put the ORDER BY.  So
> when you write it that way, the subquery is planned independently and
> it doesn't realize that it should use a fast-start plan instead of a
> minimum-total-time plan.
>
> I can think of various possible kluges to get around this in simple
> cases, but nothing I like much...
>
>             regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faqs/FAQ.html

pgsql-general by date:

Previous
From: Mike G
Date:
Subject: Re: function returning a readable representation of a number
Next
From: Carlos Roberto Chamorro Mostacilla
Date:
Subject: Re: Function and RowType