Re: Do Views offer any performance advantage? - Mailing list pgsql-performance

From Tom Lane
Subject Re: Do Views offer any performance advantage?
Date
Msg-id 8832.1050427583@sss.pgh.pa.us
Whole thread Raw
In response to Do Views offer any performance advantage?  ("Robert John Shepherd" <robert@reviewer.co.uk>)
Responses Re: Do Views offer any performance advantage?  (Andreas Pflug <Andreas.Pflug@web.de>)
List pgsql-performance
"Robert John Shepherd" <robert@reviewer.co.uk> writes:
> Whilst I often use views for convenience, is there any performance
> advantage at all in using a view rather than running the same query
> directly on the tables themselves?

No, a view is just a macro.

There is probably some minuscule cost difference involved --- you save
parsing and parse analysis of a long query string.  On the other hand,
you pay to pull the view definition from the catalogs and merge it into
the given query.  I'd not care to hazard a guess on whether the actual
net cost is more or less; but in any case these costs will be swamped
by query planning and execution, if the query is complex.

If you're concerned about reducing parse/plan overhead for repetitive
queries, the prepared-statement facility (new in 7.3) is what to look
at.  Views won't do much for you.

            regards, tom lane


pgsql-performance by date:

Previous
From: "scott.marlowe"
Date:
Subject: Re: for help!
Next
From: Greg Stark
Date:
Subject: Using indexes for like foo% type queries when foo isn't constant (not a locale issue)