Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 44E619FA0EF for ; Thu, 4 Jan 2007 01:41:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 46487-09 for ; Thu, 4 Jan 2007 01:41:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from 66-226-76-106.dedicated.abac.net (66-226-76-106.dedicated.abac.net [66.226.76.106]) by postgresql.org (Postfix) with ESMTP id 72CCC9FA0B7 for ; Thu, 4 Jan 2007 01:41:29 -0400 (AST) Received: (qmail 5213 invoked by uid 2020); 3 Jan 2007 22:47:48 -0800 Received: from wsip-70-167-125-69.sd.sd.cox.net (HELO ?192.168.0.3?) (70.167.125.69) by 192.168.0.4 with (DHE-RSA-AES256-SHA encrypted) SMTP; 3 Jan 2007 22:47:48 -0800 Message-ID: <459C93BC.30502@modgraph-usa.com> Date: Wed, 03 Jan 2007 21:42:20 -0800 From: "Craig A. James" User-Agent: Thunderbird 1.5.0.9 (X11/20061206) MIME-Version: 1.0 To: Adam Rich CC: pgsql-performance@postgresql.org Subject: Re: Trivial function query optimized badly References: <00a801c72fb7$4ad7dd50$6400a8c0@dualcore> In-Reply-To: <00a801c72fb7$4ad7dd50$6400a8c0@dualcore> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.905 tagged_above=0 required=5 tests=AWL, BAYES_50, HELO_DYNAMIC_IPADDR2 X-Spam-Level: ** X-Archive-Number: 200701/49 X-Sequence-Number: 22650 Adam Rich wrote: > Craig, > What version of postgres are you using? I just tested this on PG 8.1.2 > and was unable to reproduce these results. I wrote a simple function > that returns the same text passed to it, after sleeping for 1 second. > I use it in a where clause, like your example below, and regardless of > the number of rows in the table, it still takes roughly 1 second, > indicating to me the function is only called once. Sorry, I forgot that critical piece of info: I'm using 8.1.4. Your results would indicate that 8.1.2 creates a different plan than 8.1.4, or else there's some configuration parameter that's different between your installation and mine that causes a radically different plan to be used. I assume you vacuum/analyzed the table before you ran the query. > Is it possible that your function really isn't immutable? Would PG > realize this and fall back to treating it as VOLATILE ? Now that you say this, this seems more like a bug with the definition of IMMUTABLE. The function should only be called once if it's given a constant string, right? So the fact that Postgres called it once per row is just wrong. Craig