Re: View not using index - Mailing list pgsql-performance

From Tom Lane
Subject Re: View not using index
Date
Msg-id 19466.1118672304@sss.pgh.pa.us
Whole thread Raw
In response to Re: View not using index  (Yves Vindevogel <yves.vindevogel@implements.be>)
List pgsql-performance
Yves Vindevogel <yves.vindevogel@implements.be> writes:
> rvponp=# explain select * from vw_document_pagesperjob limit 10 ;
>                                            QUERY PLAN
> ------------------------------------------------------------------------
> ----------------------
>   Limit  (cost=82796.59..82796.72 rows=10 width=706)
>     ->  Subquery Scan vw_document_pagesperjob  (cost=82796.59..90149.20
> rows=588209 width=706)
>           ->  Sort  (cost=82796.59..84267.11 rows=588209 width=74)
>                 Sort Key: tblprintjobs.descpages,
> tblprintjobs.documentname
>                 ->  Seq Scan on tblprintjobs  (cost=0.00..26428.61
> rows=588209 width=74)
> (5 rows)

In general, putting an ORDER BY inside a view isn't a great idea ---
it's not legal per SQL spec (hence not portable), and it defeats most
forms of optimization of the view.

CVS tip is actually able to do what you wish with the above case, but no
existing release will optimize the view's ORDER BY in light of a LIMIT
that's outside the view.

            regards, tom lane

pgsql-performance by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Index ot being used
Next
From: "Kevin Grittner"
Date:
Subject: Re: Help with rewriting query