X-Original-To: pgsql-performance@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 9DD65475458 for ; Tue, 15 Apr 2003 19:37:04 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 036AA474E44 for ; Tue, 15 Apr 2003 19:37:04 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h3FNb6U6011036; Tue, 15 Apr 2003 19:37:06 -0400 (EDT) To: Andreas Pflug Cc: pgsql-performance@postgresql.org Subject: Re: Do Views offer any performance advantage? In-reply-to: <3E9C63A8.4040801@web.de> References: <001f01c30366$93427720$f3b0313e@LAIKA> <8832.1050427583@sss.pgh.pa.us> <3E9C63A8.4040801@web.de> Comments: In-reply-to Andreas Pflug message dated "Tue, 15 Apr 2003 21:55:20 +0200" Date: Tue, 15 Apr 2003 19:37:06 -0400 Message-ID: <11035.1050449826@sss.pgh.pa.us> From: Tom Lane X-Spam-Status: No, hits=-32.3 required=5.0 tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES 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/139 X-Sequence-Number: 1645 Andreas Pflug writes: > 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. This is not the view's fault though --- the same would have happened if you'd written explicitly FROM A JOIN B JOIN (D JOIN E) 7.4 will be less rigid about this (with or without a view ...) regards, tom lane