Subject | Re: SV: [firebird-support] Query optimization help |
---|---|
Author | Mark Rotteveel |
Post date | 2013-07-26T08:40:59Z |
On Fri, 26 Jul 2013 08:29:10 +0000, Poul Dige <pd@...> wrote:
more likely that the ORDER BY forces the optimizer to ignore some of the
possible optimizations (although I can't discount the possibility that
using the view adds additional restrictions for the optimizer). There is a
reason that for example SQL Server forces you to add a TOP-clause if you
define an ORDER BY in a view. Ordering a view usually only makes sense if
you want the view itself to return a limited number of rows, and in other
cases it will usually degrade performance, because intermediate sorts are
bad for performance.
Potentially the performance is similar if the query would be constructed
by inlining the view.
Mark
> We had similar performance problems with an "order by" in a view, whichis
> quite silly if the view is optimized isolated from the whole query.are
> Particularly when you want to select one single record from a view, it
> seems that it selects everything, orders it, at then returns what you
> looking for.-
>
> We simply removed the order by in the view (which completely makes sense
> why should it be there at all?) and put it in the query using the viewA view is not optimized in isolation as far as I am aware, the problem is
> instead. Much snappier!
more likely that the ORDER BY forces the optimizer to ignore some of the
possible optimizations (although I can't discount the possibility that
using the view adds additional restrictions for the optimizer). There is a
reason that for example SQL Server forces you to add a TOP-clause if you
define an ORDER BY in a view. Ordering a view usually only makes sense if
you want the view itself to return a limited number of rows, and in other
cases it will usually degrade performance, because intermediate sorts are
bad for performance.
Potentially the performance is similar if the query would be constructed
by inlining the view.
Mark