X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3B3299DC81B for ; Fri, 13 Jan 2006 20:06:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26349-07 for ; Fri, 13 Jan 2006 20:06:57 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id D87BE9DC80C for ; Fri, 13 Jan 2006 20:06:52 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id A1F5A3983E; Fri, 13 Jan 2006 18:06:40 -0600 (CST) Date: Fri, 13 Jan 2006 18:06:40 -0600 From: "Jim C. Nasby" To: Tom Lane Cc: Mark Liberman , pgsql-performance@postgresql.org Subject: Re: Stable function being evaluated more than once in a single query Message-ID: <20060114000640.GN9017@pervasive.com> References: <200601111641.20627.mliberman@mixedsignals.com> <935.1137040403@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <935.1137040403@sss.pgh.pa.us> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.089 required=5 tests=[AWL=0.089] X-Spam-Score: 0.089 X-Spam-Level: X-Archive-Number: 200601/171 X-Sequence-Number: 16649 On Wed, Jan 11, 2006 at 11:33:23PM -0500, Tom Lane wrote: > Mark Liberman writes: > > I've got a set-returning function, defined as STABLE, that I reference twice > > within a single query, yet appears to be evaluated via two seperate function > > scans. > > There is no guarantee, express or implied, that this won't be the case. > > (Seems like we just discussed this a couple days ago...) Well, from 32.6: "This category allows the optimizer to optimize away multiple calls of the function within a single query." That could certainly be read as indicating that if the function is used twice in one query it could be optimized to one call. Is the issue that the optimizer won't combine two function calls (ie: SELECT foo(..) ... WHERE foo(..)), or is it that sometimes it won't make the optimization (maybe depending on the query plan, for example)? -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461