X-Original-To: pgsql-performance@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id DD3D847633C for ; Tue, 15 Apr 2003 15:55:13 -0400 (EDT) Received: from smtp.web.de (smtp02.web.de [217.72.192.151]) by postgresql.org (Postfix) with ESMTP id DFF29474E44 for ; Tue, 15 Apr 2003 15:55:08 -0400 (EDT) Received: from p508188a2.dip0.t-ipconnect.de ([80.129.136.162] helo=web.de) by smtp.web.de with asmtp (TLSv1:RC4-MD5:128) (WEB.DE(Exim) 4.97 #53) id 195WWH-0000Sl-00 for pgsql-performance@postgresql.org; Tue, 15 Apr 2003 21:55:05 +0200 Message-ID: <3E9C63A8.4040801@web.de> Date: Tue, 15 Apr 2003 21:55:20 +0200 From: Andreas Pflug User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Do Views offer any performance advantage? References: <001f01c30366$93427720$f3b0313e@LAIKA> <8832.1050427583@sss.pgh.pa.us> In-Reply-To: <8832.1050427583@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-34.4 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,RCVD_IN_NJABL, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MOZILLA_UA autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/138 X-Sequence-Number: 1644 Tom Lane wrote: > >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. > Actually, there are cases when a view can impact performance. If you are joining a view, it seems to be treated as a subquery, that might have a much larger result than you would like. Imagine SELECT something FROM A JOIN B JOIN C ... WHERE A.primaryKeyFoo=1234 ... where C is a view, containing JOINs itself, I observed a query plan (7.3.2) like A JOIN B JOIN (D JOIN E) instead of A JOIN B JOIN D JOIN E which would be much more efficient for the A.primaryKeyFoo restriction.