Re: optimization with limit and order by in a view

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: elein <elein(at)varlena(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: optimization with limit and order by in a view
Date: 2004-07-13 21:55:50
Message-ID: 19127.1089755750@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

elein <elein(at)varlena(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas F.O'Connell 2004-07-13 22:40:24 Indexes and Tables: Growth and Treatment (Modified by Thomas F. O'Connell)
Previous Message elein 2004-07-13 21:06:58 optimization with limit and order by in a view