RE: [GENERAL] slow queries - Mailing list pgsql-general

From Jackson, DeJuan
Subject RE: [GENERAL] slow queries
Date
Msg-id F10BB1FAF801D111829B0060971D839F432E37@cpsmail
Whole thread Raw
List pgsql-general
> On Fri, 25 Sep 1998, Jackson, DeJuan wrote:
> > > seems that by creating a view ( with the query i mentioned before
> ),
> > > my
> > > queries were sped up by roughly 10 seconds... odd odd odd.
> > >
> > Not really so odd when you think of everything the backend has to do
> to
> > process a query.  Parsing, planning, and optimizing (not necessarily
> in
> > that order) can be very costly.  A view basically skips most of
> those
> > three steps.
>
> all thats taken out is the parsing bit.  the planning and optimizing
> still
> must be done ( unless its done when the view is/was created ), yesno ?
> the view should still hit the indexes created for the underlying
> tables,
> right ?
>
Well, a view in the system is really just a stored plan.  The actual
text isn't stored afaik.  So, that tells me that there's a good chance
that the optimization step won't be revisited unless the view is
dropped.  And since the plan is the last step of the optimization step
I'd say you bypass a good deal of code.  The draw back being that if the
plan isn't redone for major table changes then the query will not be the
most efficient plan, such as adding of an index that would effect the
query or additional rows in one of the tables which would make the cost
of an index scan cheaper than a table scan.

To answer your second question; it will hit the indexes if the plan that
was stored when the view was created hit those indexes.

pgsql-general by date:

Previous
From: Alexzander Blashko
Date:
Subject: Wisconsin Benchmark
Next
From: bboyd@istmail.com
Date:
Subject: unsubscribe