Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id EA7AE9FB464 for ; Fri, 6 Apr 2007 15:34:52 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 71552-04 for ; Fri, 6 Apr 2007 15:34:49 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id E329A9FB425 for ; Fri, 6 Apr 2007 15:34:48 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l36IYmo3015903; Fri, 6 Apr 2007 14:34:48 -0400 (EDT) To: "Jonathan Ellis" cc: pgsql-performance@postgresql.org Subject: Re: Premature view materialization in 8.2? In-reply-to: References: <28349.1175838196@sss.pgh.pa.us> <261.1175840636@sss.pgh.pa.us> <15092.1175881227@sss.pgh.pa.us> <15399.1175882434@sss.pgh.pa.us> Comments: In-reply-to "Jonathan Ellis" message dated "Fri, 06 Apr 2007 12:03:50 -0600" Date: Fri, 06 Apr 2007 14:34:48 -0400 Message-ID: <15902.1175884488@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/175 X-Sequence-Number: 24052 "Jonathan Ellis" writes: > It was in my original post unless it got clipped: Sorry, I had forgotten. > The problem seems to be that clan_members_v contains a call to an > expensive function: I'll bet that the function is marked VOLATILE. 8.2 is more conservative about optimizing away volatile functions than previous releases. If it has no side effects, mark it STABLE (or can it even be IMMUTABLE?). In some quick testing, I verified that 8.2 does evaluate the function at the join level corresponding to the view's join (and I think this is preventing it from considering other join orders, too). If you change the function's marking to be nonvolatile then the function disappears from the plan entirely, and also it seems to prefer joining "clans" sooner. regards, tom lane